Forum Discussion
Comparing Current Price to Previous PRice
- Anonymous4 years ago
Hi Anonymous
My Sample:
Try measure codes as below.
Current Price = VAR _LastDate = MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Product] = MAX ( 'Table'[Product] ) ), 'Table'[Date] ) VAR _CurrentPrice = CALCULATE ( MAX ( 'Table'[List Price] ), FILTER ( ALL ( 'Table' ), AND ( 'Table'[Product] = MAX ( 'Table'[Product] ), 'Table'[Date] = _LastDate ) ) ) RETURN _CurrentPricePrevious Price = VAR _LastDate = MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Product] = MAX ( 'Table'[Product] ) ), 'Table'[Date] ) VAR _PreviousDate = CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( ALL ( 'Table' ), 'Table'[Product] = MAX ( 'Table'[Product] ) && 'Table'[Date] < _LastDate && 'Table'[List Price] <> [Current Price] ) ) VAR _PreviousPrice = CALCULATE ( MAX ( 'Table'[List Price] ), FILTER ( ALL ( 'Table' ), AND ( 'Table'[Product] = MAX ( 'Table'[Product] ), 'Table'[Date] = _PreviousDate ) ) ) RETURN _PreviousPriceThen create a matrix add Product in Column field in Matrix and add measures in Value field. Then use Show on row function in Matrix format. Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous
My Sample:
Try measure codes as below.
Current Price =
VAR _LastDate =
MAXX (
FILTER ( ALL ( 'Table' ), 'Table'[Product] = MAX ( 'Table'[Product] ) ),
'Table'[Date]
)
VAR _CurrentPrice =
CALCULATE (
MAX ( 'Table'[List Price] ),
FILTER (
ALL ( 'Table' ),
AND ( 'Table'[Product] = MAX ( 'Table'[Product] ), 'Table'[Date] = _LastDate )
)
)
RETURN
_CurrentPrice
Previous Price =
VAR _LastDate =
MAXX (
FILTER ( ALL ( 'Table' ), 'Table'[Product] = MAX ( 'Table'[Product] ) ),
'Table'[Date]
)
VAR _PreviousDate =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
ALL ( 'Table' ),
'Table'[Product] = MAX ( 'Table'[Product] )
&& 'Table'[Date] < _LastDate
&& 'Table'[List Price] <> [Current Price]
)
)
VAR _PreviousPrice =
CALCULATE (
MAX ( 'Table'[List Price] ),
FILTER (
ALL ( 'Table' ),
AND (
'Table'[Product] = MAX ( 'Table'[Product] ),
'Table'[Date] = _PreviousDate
)
)
)
RETURN
_PreviousPrice
Then create a matrix add Product in Column field in Matrix and add measures in Value field. Then use Show on row function in Matrix format. Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
This formula is a killer!
How would you change the dax to filter by vendor for the same product? Anonymous
Thanks!