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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
vinceluc22
Regular Visitor

Determine if a State is open in between two dates.

StateDateCases
Alabama1/1/20201
Alabama1/2/20202
Alabama1/3/20203
Alabama1/4/20204
Alabama1/5/20205
Alaska1/1/20201
Alaska1/2/20202
Alaska1/3/20203
Alaska1/4/20204

 

Above is a sample dataset. I'm trying to create a new column that evaluates Alabama and output OPEN if the Date is between 1/2/2020 and 1/4/2020. Otherwise, output CLOSED as the result. 

 

I tried adding a Quick Measure with a nested IF and DATESBETWEEN statement but it didn't work. It prints CLOSED for all of Alabama.

 

NewColumn = if('MyTable'[State] = "Alabama",if(DATESBETWEEN('MyTable'[Date],1/2/2020, 1/4/2020), "OPEN", "CLOSED"))

Any idea on how to get the result below?

 

StateDateCasesNewColumn
Alabama1/1/20201CLOSED
Alabama1/2/20202OPEN
Alabama1/3/20203OPEN
Alabama1/4/20204OPEN
Alabama1/5/20205CLOSED
Alaska1/1/20201 
Alaska1/2/20202 
Alaska1/3/20203 
Alaska1/4/20204 

 

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @vinceluc22 ,

 

Try this code for a calculated column:

 

Column =
IF('Table'[State] = "ALABAMA";
IF('Table'[Date] >= DATE(2020;2;1) && 'Table'[Date] <= DATE(2020;4;1); "OPEN"; "CLOSED"))
 
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

2 REPLIES 2
camargos88
Community Champion
Community Champion

Hi @vinceluc22 ,

 

Try this code for a calculated column:

 

Column =
IF('Table'[State] = "ALABAMA";
IF('Table'[Date] >= DATE(2020;2;1) && 'Table'[Date] <= DATE(2020;4;1); "OPEN"; "CLOSED"))
 
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Thank You! Seems like the DATESBETWEEN statement wasn't needed.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.