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
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 difference between dates, my Delta works for most scenarios. However, there are cases where the measure is not working, specifically when we have 0 for the maximum date and a positive value > 0 for the minimum date.
Here is the DAX I am using for my Delta, in my Measure:
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] ) )
)
)
)
The screenshot below shows that my Delta works perfectly when calculating the difference for the selected dates and rows below.
Here follows one example where my measure is not working, where I have 0 for the maximum date and a positive value > 0 for the minimum date:
For the highlighted row, the delta should be -0.1 instead.
All other rows in this matrix are making sense.
Can someone please help me out with this issue?
Thank you 🐾
Hi @Martin_D
The solution you provided solves the delta issue when the latest date value is blank. The screenshot below shows the results of your DAX function.
However, it is not ideal because it converts the minimum date values to negative, which works fine for the delta calculation but can be wrongly interpreted by users, since these are positive orders from July 5th.
I am considering as a second option to work on the data and insert values for dates where I do not have any order data. Please let me know if there is an easier solution.
Thank you so much!!!
Best,
Diane
Hi @dianecrz ,
Would you like to provide a sample file? As long as the dates in the column headers come from Table[Snapshot Date] the measures shouldn't impact the sign (_Sign factor is one in this case).
BR
Martin
Hi 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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
23 | |
15 | |
12 | |
9 | |
8 |
User | Count |
---|---|
41 | |
32 | |
29 | |
12 | |
12 |