Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Bucephalus-lgtm/1a38ab9269ad5cad8586c77cea5da6b8 to your computer and use it in GitHub Desktop.
Save Bucephalus-lgtm/1a38ab9269ad5cad8586c77cea5da6b8 to your computer and use it in GitHub Desktop.

Prompt: Make certain date ranges come out with different answers in a Google Sheet

Overview

In this prompt, you will create a Google Sheet table that assigns different values to different date ranges using an IF statement. This can be useful if you need to analyze data that spans multiple time periods and want to assign different categories or labels to each period.

Steps

  1. Open a new Google Sheet and create a table with three columns: "Start Date," "End Date," and "Result."

  2. Enter a range of dates in the "Start Date" column that covers at least two different time periods (e.g., January 1, 2022 - March 31, 2022 and April 1, 2022 - June 30, 2022).

  3. In the "End Date" column, enter the corresponding end dates for each time period.

  4. In the "Result" column, use an IF statement to assign a different value to each time period.

  5. For example, you could use the following formula:

=IF,(AND(A2>=DATE(2022,1,1),A2<=DATE(2022,3,31)), "Period 1", 
IF(AND(A2>=DATE(2022,4,1),A2<=DATE(2022,6,30)), "Period 2", "N/A"))

This formula checks whether the date in column A falls within the first period (January 1, 2022 - March 31, 2022) or the second period (April 1, 2022 - June 30, 2022), and returns the corresponding value ("Period 1" or "Period 2"). If the date doesn't fall within either period, it returns "N/A."

  1. Copy the formula down to apply it to all rows in the table.

  2. Test the formula by entering a few different dates in the "Start Date" column and checking that

  3. the correct result appears in the "Result" column.

You can modify the IF statement to include as many different time periods as you need, and adjust the date ranges and result values as necessary. With this prompt, you can easily assign different values to different date ranges in your Google Sheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment