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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
Microsoft Employee
Microsoft 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
Microsoft Employee
Microsoft 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
Community Champion
Community Champion

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-...

 

 



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...

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Solution Authors