Forum Discussion
dianecrz
3 years agoFrequent Visitor
DAX Delta Issue - Difference Between Dates Not Working When Amount is Zero for Maximum Date Selected
I am trying to accurately calculate the difference in the amount sold between the most recent date selected and the oldest one. I used a DAX formula to create my Delta, and when calculating the diff...
Martin_D
Solution Sage
3 years agoHi dianecrz,
in the context of the highlighted row, 17-May-23 is your min date because there are no orders on 29-May-22 in the context of this row. The yellow line executes the first calcualtion of your IF statement (Table[Snapshot_Date] has one value], even in the context of the Delta column).
You could try adding another IF to invert the sign if the row has only one date with orders an it's not the max date in the context, like:
Diff =
VAR _Sign =
IF (
ISISNCOPE ( Table[Snapshot_Date] ),
1,
VAR _MaxRowDate = MAX ( Table[Snapshot_Date] )
VAR _MaxVisualDate =
CALCULATE (
MAX ( Table[Snapshot_Date] ),
ALLSELECTED ()
)
RETURN
IF (
_MaxRowDate = _MaxVisualDate,
-1,
1
)
)
VAR _Diff =
IF (
HASONEVALUE ( Table[Snapshot_Date] ),
SUM ( Table[Orders] ),
CALCULATE (
SUM( Table[Orders] ),
FILTER (
Table,
Table[Snapshot_Date] = MIN ( Table[Snapshot_Date] )
)
)
- CALCULATE (
SUM ( Table[Orders] ),
FILTER (
Table,
Table[Snapshot_Date] = MAX ( Table[Snapshot_Date] )
)
)
)
RETURN
_Sign * _Diff