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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
1241pm
Frequent Visitor

DATEDIFF Function with certain provisions

Hello,

I have 3 columns on table 1 , "Value" , "Type", and "Date".  Type includes projections for Sales and Expenses.  The Dates column ranges from Sep 2016-Dec 2018 for Sales and from Sep 2017-Dec 2019 for Expenses. I am currently trying to find the date diff from the minimum date for seperatly for sales and expenses in one column. Is there a function I could use DATEDIFF with in conjuction with something like "WHERE [Value]= Sales OR Expenses"?  In result, I should get a new column where Sep 2016 for Sales=0 as well as Sep 2017 for Expenses=0.  Please let me know if anyone needs a little clarification. Thank you so much for your time.

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @1241pm,

 

Please check if the following DAX return your expected result, if not, kindly share your sample to me and post desired result  based on the sample.

 Column 2 = IF(Table1[Type]= "Sales",1,0)
date1 = CALCULATE(MIN(Table1[Date]),FILTER(ALL(Table1),Table1[Column 2]=1))
date2 = CALCULATE(MIN(Table1[Date]),FILTER(ALL(Table1),Table1[Column 2]=0))
Result = IF(Table1[Column 2]=1,DATEDIFF(Table1[date1],Table1[Date],DAY),DATEDIFF(Table1[date2],Table1[date],DAY))

 

 

image001.png

 

For more details, please check the pbix as attached.

https://www.dropbox.com/s/pkd9a4a2d2saxvr/DATEDIFF%20Function%20with%20certain%20provisions.pbix?dl=...

 

Regards,
Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

1 REPLY 1
v-frfei-msft
Community Support
Community Support

Hi @1241pm,

 

Please check if the following DAX return your expected result, if not, kindly share your sample to me and post desired result  based on the sample.

 Column 2 = IF(Table1[Type]= "Sales",1,0)
date1 = CALCULATE(MIN(Table1[Date]),FILTER(ALL(Table1),Table1[Column 2]=1))
date2 = CALCULATE(MIN(Table1[Date]),FILTER(ALL(Table1),Table1[Column 2]=0))
Result = IF(Table1[Column 2]=1,DATEDIFF(Table1[date1],Table1[Date],DAY),DATEDIFF(Table1[date2],Table1[date],DAY))

 

 

image001.png

 

For more details, please check the pbix as attached.

https://www.dropbox.com/s/pkd9a4a2d2saxvr/DATEDIFF%20Function%20with%20certain%20provisions.pbix?dl=...

 

Regards,
Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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