Forum Discussion

StevenMorgan81's avatar
StevenMorgan81
New Member
3 years ago
Solved

Identify if a date is between multiple ranges

Hi folks,

 

Looking for a bit of help in adding a Custom Column to define if a date is between two sets of date ranges i.e. If [Date] Between [Valid Start 1] and [Valid End 1] then Valid else If [Date] [Valid Start 2] and [Valid End 2]  then "Valid" else "Invalid".

 

[Valid Start/End 2] may contain null values where it is not present in the dataset.

 

Sample Table:

DateValid Start 1Valid End 1Valid Start 2Valid End 2Valid?
01/06/2022       01/01/2021      nullnullnullValid
01/06/202201/01/202101/12/2022     nullnullValid
01/06/202201/01/202101/01/2022nullnullInvalid
01/06/202201/01/202131/12/202101/04/2022    nullValid
01/06/202201/01/202101/01/202201/04/202201/07/2022      Valid
01/06/202201/01/202101/01/202201/04/202201/05/2022Invalid

 

The Valid Start / End dates are actually stored in a different table and have been appended by merging tables - if its easier to "lookup" without the merge no problem going down that route.

 

Any help very welcome.

 

Steve

 

  • StevenMorgan81 Add a custom column like: 

    = if ( [Date] >= [Valid Start 1] and ( [Valid End 1] = null or [Date] <= [Valid End 1]) and not([Valid Start 1] = null and [Valid End 1] = null ) ) or ( [Date] >= [Valid Start 2] and ( [Valid End 2] = null or [Date] <= [Valid End 2]) and not([Valid Start 2] = null and [Valid End 2] = null ) ) then "Valid" else "Invalid"

1 Reply

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    StevenMorgan81 Add a custom column like: 

    = if ( [Date] >= [Valid Start 1] and ( [Valid End 1] = null or [Date] <= [Valid End 1]) and not([Valid Start 1] = null and [Valid End 1] = null ) ) or ( [Date] >= [Valid Start 2] and ( [Valid End 2] = null or [Date] <= [Valid End 2]) and not([Valid Start 2] = null and [Valid End 2] = null ) ) then "Valid" else "Invalid"