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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Datediff is not calculating as expected

Hi,

 

Datediff is not calculating correctly, I want to calculate the difference in days between the max date and mindate of a particular date column (Production Date Time).

 

Date diff = DATEDIFF(max('Fact'[Production Date-Time]),min('Fact'[Production Date-Time]),DAY)

 

Can you please let me know what am i doing wrong here?

 

datediff1.PNGdatediff2.PNG

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

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario.

Fact:

a1.png

 

You may create a measure like follows.

 

Date Diff = 
DATEDIFF(
    CALCULATE(MAX('Fact'[Production Date-Time]),ALLSELECTED('Fact')),
    CALCULATE(MIN('Fact'[Production Date-Time]),ALLSELECTED('Fact')),
    DAY
)

 

 

Result:

a2.png

 

Best Regards

Allan

 

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

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario.

Fact:

a1.png

 

You may create a measure like follows.

 

Date Diff = 
DATEDIFF(
    CALCULATE(MAX('Fact'[Production Date-Time]),ALLSELECTED('Fact')),
    CALCULATE(MIN('Fact'[Production Date-Time]),ALLSELECTED('Fact')),
    DAY
)

 

 

Result:

a2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks , this works. I was actually making those date diff calculations in calculated column, when i used measures its working.

I also tried 

test date diff = 1.*([Minimum Prod date] - [max prod date]) in measure, this also works 🙂
 
 
amitchandak
Super User
Super User

Date diff measure requires context.  Refer :https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors