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
Stuznet
Helper V
Helper V

Calculate Number of Days Between Three Dates

Hi,
I’m scratching my heads how to write this logic.
In the data source, I have 3 dates. I want to write a datediff function between three dates.

Capture.PNG


Here is my logic
Date 1 minus the earlier Date2 or Date 3.

How do I write DATEDIFF based on this logic?

Thank you

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @Stuznet ,

 

Based on my understanding, you want to calculate the days between [Date1] and the latested date from [Date2] and [Date3], right? In other words, if [Date2] is earlier than [Date3], you want the datediff between [Date1] and [Date3], otherwise, calculate the diff between [Date1] and [Date2].

 

Please refer to below measure.

Datediff =
DATEDIFF ( MAX ( [Date1] ), MAX ( MAX ( [Date2] ), MAX ( [Date3] ) ), DAY )

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

6 REPLIES 6
v-yulgu-msft
Employee
Employee

Hi @Stuznet ,

 

Based on my understanding, you want to calculate the days between [Date1] and the latested date from [Date2] and [Date3], right? In other words, if [Date2] is earlier than [Date3], you want the datediff between [Date1] and [Date3], otherwise, calculate the diff between [Date1] and [Date2].

 

Please refer to below measure.

Datediff =
DATEDIFF ( MAX ( [Date1] ), MAX ( MAX ( [Date2] ), MAX ( [Date3] ) ), DAY )

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.

@v-yulgu-msft 

 

Thank you so much!! 🙂 I wouldn't have figured it out.

Anonymous
Not applicable

Can you post some an example of what you would want? Not entirely clear

@Greg_Deckler  

I'm not sure I'm following

 

@Anonymous 

Here is the dummy report

 

Greg_Deckler
Super User
Super User

Depends on your data structure, but you want to get the MIN and the MAX and subtract those two. If these are in three columns, you can use my MC Aggregations Quick Measure to get the MIN and MAX of the three columns.

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Multi-Column-Aggregations-MC-Aggregations/m-...

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler 

 

So I followed your sample and created Max and I'm kinda lost. 

MC Max = 
VAR Date2 = SELECTCOLUMNS('Date',"Date",[Date2])
VAR Date3 = SELECTCOLUMNS('Date',"Date",[Date3])
VAR tmpTable = UNION(Date2,Date3)
VAR tmpValue = MAXX(tmpTable,[Date])
RETURN tmpValue

Then create another calculated column

DaysBetween = DATEDIFF('Date'[MC Max], [Date1], DAY)

 What am I doing wrong here?

Capture.PNG

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.