cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Stuznet Member
Member

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

Accepted Solutions
v-yulgu-msft Super Contributor
Super Contributor

Re: Calculate Number of Days Between Three Dates

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
Super User
Super User

Re: DATEDIFF Between Three Dates

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

 

 


I have book! Learn Power BI from Packt


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

Proud to be a Datanaut!

Super User
Super User

Re: DATEDIFF Between Three Dates

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

Stuznet Member
Member

Re: DATEDIFF Between Three Dates

@Greg_Deckler  

I'm not sure I'm following

 

@Nick_M 

Here is the dummy report

 

Stuznet Member
Member

Re: DATEDIFF Between Three Dates

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

v-yulgu-msft Super Contributor
Super Contributor

Re: Calculate Number of Days Between Three Dates

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

Stuznet Member
Member

Re: Calculate Number of Days Between Three Dates

@v-yulgu-msft 

 

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

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 65 members 1,183 guests
Please welcome our newest community members: