Search code examples
if-statementgoogle-sheetsexcel-formulagoogle-sheets-formulaarray-formulas

IF event has occurred at X location within Y days, return Z value (Excel or Google Sheets)


I have an Events data set of recurring events with each event as a row and each column as data associated with that event. There is a date and location for each event. New locations are added on a regular basis. Sometimes these events stop going to a particular location. I have a separate Locations sheet with a list of locations, and I would like to classify locations as "Active" or "Inactive" to know if they are actively receiving this event.

The events are health outreach clinics, but you could also think of them as a package being delivered or a site visit being conducted.

I want to classify locations under this typology:

  • "Active" if event has occurred within the last 90 days
  • "Inactive" if event last occurred over 90 days ago

What formula should I use?

Here is a sample file and screenshots: https://docs.google.com/spreadsheets/d/1tn1tSza-hza1qVKotEcMyNBktZTlExBB5MQBlcyfkP8/edit?usp=sharing

Events Sheet screenshot

Locations Sheet screenshot

Thanks in advance!


Solution

  • paste in B2

    =ARRAYFORMULA(IF(REGEXMATCH(FILTER(A2:A, A2:A<>""), TEXTJOIN("|", 1, 
     FILTER(Events!B2:B, Events!A2:A>=TODAY()-90))), "active", "inactive"))
    

    0