Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
StevenMorgan81
New Member

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

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
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"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Community Champion
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"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.