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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rbustamante
Helper I
Helper I

Calculate difference between columns in matrix visual

I have the following matrix visual:

rbustamante_0-1609977347658.png

I need two things when the user clicks on the "Date slicer":

1) dynamically calculate the difference between the ammount of two dates. Ammount of 31/12/2020 less ammount of 30/04/2020.

2) dynamically calculate the difference between the ammount of the last date 31/12/2020 and the ammount of the first date 31/12/2019

1 ACCEPTED SOLUTION
Payeras_BI
Solution Sage
Solution Sage

Hi @rbustamante ,

 

Based on the data you provided here: 

 

https://community.powerbi.com/t5/DAX-Commands-and-Tips/How-to-calculate-measure-based-on-previous-da... 

 

 

mDifference = 
VAR _CurrentDate =
    SELECTEDVALUE ( 'Products (2)'[Date])
VAR _PreviousDate =
    CALCULATE (
        MAX ( 'Products (2)'[Date] ),
        ALLSELECTED ( 'Products (2)'[Date] ),
        KEEPFILTERS ( 'Products (2)'[Date] < _CurrentDate )
    )
VAR _ThisMonth =
    CALCULATE ( SUM ( 'Products (2)'[Amount] ) )
VAR _PreviousMonth =
    CALCULATE (
        SUM ( 'Products (2)'[Amount] ),
        'Products (2)'[Date] = _PreviousDate
    )
RETURN
    _ThisMonth - _PreviousMonth

 

 

Payeras_BI_0-1610379950367.png

Regards,

 

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

View solution in original post

6 REPLIES 6
Payeras_BI
Solution Sage
Solution Sage

Hi @rbustamante ,

 

Based on the data you provided here: 

 

https://community.powerbi.com/t5/DAX-Commands-and-Tips/How-to-calculate-measure-based-on-previous-da... 

 

 

mDifference = 
VAR _CurrentDate =
    SELECTEDVALUE ( 'Products (2)'[Date])
VAR _PreviousDate =
    CALCULATE (
        MAX ( 'Products (2)'[Date] ),
        ALLSELECTED ( 'Products (2)'[Date] ),
        KEEPFILTERS ( 'Products (2)'[Date] < _CurrentDate )
    )
VAR _ThisMonth =
    CALCULATE ( SUM ( 'Products (2)'[Amount] ) )
VAR _PreviousMonth =
    CALCULATE (
        SUM ( 'Products (2)'[Amount] ),
        'Products (2)'[Date] = _PreviousDate
    )
RETURN
    _ThisMonth - _PreviousMonth

 

 

Payeras_BI_0-1610379950367.png

Regards,

 

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain
AntrikshSharma
Super User
Super User

@rbustamante  Should be pretty easy, share a PBIX file with sample data.

Sorry it is not posible to share the pbix file

Thanks for your reply.

I try to explain better:

rbustamante_0-1610066199526.png

In this case I choose 3 dates and I need to know de difference between Ammount 31/03/2020 and 31/12/2019 and the difference between 30/04/2020 and 31/03/2020.

If I choose different dates I need to know the diferences between amounts at these dates.

I share the file

 

 

amitchandak
Super User
Super User

@rbustamante , With help from date table , First seem diff day vs last

Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

 

This Day = CALCULATE([sales], FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])))

 

Diff = [This Day] - [Last Day Non Continuous]

 

Between first and last date

 

new measure =
var _min = minx(allselected('Date'), 'Date'[Date])
var _max = maxx(allselected('Date'), 'Date'[Date])
return
calculate([measure], filter( 'Date', 'Date'[Date] =_max )) -calculate([measure], filter( 'Date', 'Date'[Date] =_min )))

 

or

 

new measure =
var _min = minx(allselected('Date'), 'Date'[Date])
var _max = maxx(allselected('Date'), 'Date'[Date])
return
calculate([measure], filter( Table, Table[Date] =_max )) -calculate([measure], filter( Table, Table[Date] =_min )))

 

Use date Table

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

 

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

Thank for the response but not works. It is not posible to know the difference between months.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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