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
gusdahu
Helper IV
Helper IV

How to create a measurement to act like an if statement?

Hello,

 

Currently I am using direct SQLto upload data into Power BI. As you all know, direct SQL disables many of Power BI's functionalities such as creating conditional columns among others. How may I create an if statement in Power BI using the measurement feature to compare two dates? Basically I have a PO Date and an Invoice date. I would like the measure to count the number of instances the invoice date is prior to the PO date.

 

Any help would be much appreciated.

 

Regards,

Gus Dahu

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @gusdahu,

 

Please try below measures:

check = IF(MAX(Table1[Invoice date])<MAX(Table1[PO Date]),1,0)
count = CALCULATE(COUNTROWS(Table1),FILTER(Table1,[check]=1 ))

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @gusdahu,

 

Please try below measures:

check = IF(MAX(Table1[Invoice date])<MAX(Table1[PO Date]),1,0)
count = CALCULATE(COUNTROWS(Table1),FILTER(Table1,[check]=1 ))

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Yuliana,

 

Thank you for your response!

 

After I type in the formula into my measurement, should the table automatically populate with a new column for the measurement? I attempted to manually add the measurement to the table, however I get the rejection "Can't display visual. See details". I have no idea what I am doing wrong.

 

Regards,

Gus Dahu

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.