Forum Discussion
Calculating the difference dynamically, based on Year selection
- 2 years ago
Hi, I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
I hope the below can provide some ideas on how to create a solution for your semantic model.
compare to the previous within the slicer selection: = VAR _currentselectsales = SUM ( Sales[Sales] ) VAR _currentselectyear = MAX ( 'Year'[Year] ) VAR _prevselectyear = MAXX ( FILTER ( ALLSELECTED ( 'Year' ), 'Year'[Year] < _currentselectyear ), 'Year'[Year] ) VAR _prevselectsales = CALCULATE ( SUM ( Sales[Sales] ), 'Year'[Year] = _prevselectyear ) RETURN IF ( NOT ISBLANK ( _prevselectsales ), _currentselectsales - _prevselectsales ) - 2 years ago
Jihwan_Kim Perfect.
- 2 years ago
Perfect
Hi, I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
I hope the below can provide some ideas on how to create a solution for your semantic model.
compare to the previous within the slicer selection: =
VAR _currentselectsales =
SUM ( Sales[Sales] )
VAR _currentselectyear =
MAX ( 'Year'[Year] )
VAR _prevselectyear =
MAXX (
FILTER ( ALLSELECTED ( 'Year' ), 'Year'[Year] < _currentselectyear ),
'Year'[Year]
)
VAR _prevselectsales =
CALCULATE ( SUM ( Sales[Sales] ), 'Year'[Year] = _prevselectyear )
RETURN
IF ( NOT ISBLANK ( _prevselectsales ), _currentselectsales - _prevselectsales )
- MarshalSK2 years agoResolver I
Jihwan_Kim One more quick question. How to apply filter>70, on top of the above result?
- Jihwan_Kim2 years agoSuper User
Hi, I am not sure if I understood your question correctly, but do you mean something like below?
compare to the previous within the slicer selection: = VAR _currentselectsales = SUM ( Sales[Sales] ) VAR _currentselectyear = MAX ( 'Year'[Year] ) VAR _prevselectyear = MAXX ( FILTER ( ALLSELECTED ( 'Year' ), 'Year'[Year] < _currentselectyear ), 'Year'[Year] ) VAR _prevselectsales = CALCULATE ( SUM ( Sales[Sales] ), 'Year'[Year] = _prevselectyear ) RETURN IF ( NOT ISBLANK ( _prevselectsales ) && _currentselectsales - _prevselectsales > 70, _currentselectsales - _prevselectsales )- BUSH7812 years agoNew Member
I'm trying to bring in the same functionality and trying to use this same DAX but it's throwing an error.
- MarshalSK2 years agoResolver I
Perfect