March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi all.
In excel there is a feature to calculate or show the values in a Pivot Table based on the difference of the previous record. I show the option:
I'm trying to do this in DAX but it doesn't run ok. I have a table with the amounts of products at a given date and the product name. I made the following measure:
Solved! Go to Solution.
Hi @rbustamante ,
For non contiguous months try this one:
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
Regards,
Hi @rbustamante ,
For non contiguous months try this one:
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
Regards,
@rbustamante , you might want to try
mDifference =
VAR _ThisMonth = CALCULATE ( SUM ( 'Products (2)'[Amount] ) )
VAR _PreviousMonth = CALCULATE ( SUM ( 'Products (2)'[Amount] ), PREVIOUSMONTH ( 'Products (2)'[Date] ) )
RETURN
_ThisMonth - _PreviousMonth
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Thanks for the response, but doesn't work if I choose non contiguous dates, for example 11/30/2020 and 12/31/2019
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
22 | |
19 | |
16 | |
9 | |
5 |
User | Count |
---|---|
37 | |
29 | |
16 | |
14 | |
12 |