Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be 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

Reply
dianecrz
Frequent 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 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.

 

DeltaWorking.png

 

 

 

 

 

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:

 

Delta_Issue_PBI.png




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 🐾

 

3 REPLIES 3
dianecrz
Frequent Visitor

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. 

NewDiff_Screenshot.PNG

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

Martin_D
Super User
Super User

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.