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
Anonymous
Not applicable

Calculation of difference of values between dates

Hello 

I'm trying to find a formula whit DAX formulas to calculate the difference of values ​​between dates.

For example I'd like to calculate the difference between date 29/10/2018 and 05/11/2018, and the result would be 9.3, or beeing able to choose another date of comparison like 26/11/2018 (result -18.62 ) in a slicer or filter.

 

Thanks in advance!

 

Capture 1.PNG

6 REPLIES 6
Syndicate_Admin
Administrator
Administrator

In my case I have this database and I would like to make a measure that gives me how many days it has taken to carry out the management.

mmelerof_0-1667927385663.png

I don't know if anyone can help me 🙂

Anonymous
Not applicable

Also, the calculation is calculated on values of another column (in this case Tons as shown in the picture),  not to calculate how many days of months are between dates.

amitchandak
Super User
Super User

@Anonymous , Assume you have taken a slicer with two date. Prefer a date calendar

 

Try measure

Measure =
var _max = maxx(allselected('Date'),'Date'[Date])
var _min = minx(allselected('Date'),'Date'[Date])
return
calculate(sum(table[tons]),filter(All(DATE), Date[Date] =_max)) - calculate(sum(table[tons]),filter(All(DATE), Date[Date] =_min))

 

or

Measure =
var _max = maxx(allselected('Date'),'Date'[Date])
var _min = minx(allselected('Date'),'Date'[Date])
return
calculate(sum(table[tons]),filter(Allselected(DATE), Date[Date] =_max)) - calculate(sum(table[tons]),filter(Allselected(DATE), Date[Date] =_min))

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
Anonymous
Not applicable

Thanks for you response!..I'm having a problem that in the 5th and 6th line (in line 2 and 3 works fine), BI doesn't recognice the table Date, since I created this Date table as a calendar. Any ideas?

 

Capture2.PNG

 

 

Hi @Anonymous ,

 

You need to modify @amitchandak's formula according to your data model, like this.

Measure = 
VAR x = 
CALCULATE(
    SUM('Table'[tons]),
    FILTER(
        ALLSELECTED('Table'),
        'Table'[Release Date] = MAXX( ALLSELECTED('Table'), [Release Date])
    )
)
VAR y = 
CALCULATE(
    SUM( 'Table'[tons] ),
    FILTER(
        ALLSELECTED('Table'),
        'Table'[Release Date] = MINX( ALLSELECTED('Table'), [Release Date] )
    )
)
RETURN
x -y

mn7.PNG

 

Best regards,
Lionel Chen

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

 

Pragati11
Super User
Super User

Hi @Anonymous ,

 

You can use DATEDIFF function in Power BI to calculate difference between 2 dates. Refer following for details:

https://docs.microsoft.com/en-us/dax/datediff-function-dax

 

If this helps and resolves the issue, appreciate a Kudos and mark it as a Solution! 🙂

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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
Top Kudoed Authors