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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Difference between column criteria base on calculated table

Hi all,

 

I created a calculuated table from my data model with the following syntax:

 

Test Table = SUMMARIZECOLUMNS
(OrderIntakeTable[Time_stamp],
OrderIntakeTable[Season],
"Total Ordered",SUM(OrderIntakeTable[Ordered quantity]))

Below result from the calculated table:

 

 

Time_stampAW 2017AW 2018SS 2018SS 2019Grand Total
2018.201,688,3731,864,7912,162,954962,2976,678,415
2018.211,688,3731,860,8672,167,3591,012,1526,728,751
2018.221,688,3731,860,6272,167,5391,017,6416,734,180
2018.231,685,4841,858,2912,167,6011,030,8616,742,237
2018.241,685,4841,858,2752,166,3231,077,1606,787,242
2018.251,685,4841,857,9492,166,1961,078,0696,787,698

 

How do I find the difference between each row Grand Total to get below output on column Differences in PowerBI?

 

Calculation logic: Row 2 - Row 1, Row 3 - Row 2, etc...

If it's in excel I could just use cell reference to calculate the difference.

 

Time_stampAW 2017AW 2018SS 2018SS 2019Grand TotalDifferences
2018.201,688,3731,864,7912,162,954962,2976,678,4150
2018.211,688,3731,860,8672,167,3591,012,1526,728,75150,336
2018.221,688,3731,860,6272,167,5391,017,6416,734,1805,29
2018.231,685,4841,858,2912,167,6011,030,8616,742,2378,057
2018.241,685,4841,858,2752,166,3231,077,1606,787,24245,005
2018.251,685,4841,857,9492,166,1961,078,0696,787,698456

 

Appreciate all the help!

 

Regards

Hidayat

9 REPLIES 9
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi Hidayat,

 

Try this formula please.

Column =
VAR currentTimeStamp = [Time_stamp]
VAR lastTimeStamp =
    CALCULATE (
        MAX ( Table1[Time_stamp] ),
        FILTER ( 'Table1', Table1[Time_stamp] < currentTimeStamp )
    )
RETURN
    IF (
        ISBLANK ( lastTimeStamp ),
        0,
        [Grand Total]
            - CALCULATE (
                SUM ( Table1[Grand Total] ),
                FILTER ( Table1, Table1[Time_stamp] = lastTimeStamp )
            )
    )

Difference_between_column_criteria_base_on_calculated_table

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi Dale,

 

The dax work, but it's not the desired output.

 

My data is repeated on rows instead of column.

 

powerbi.JPG

 

When displayed on matrix visual, it did not give the correct calculation.

 

table.JPG

Regards

Hidayat

Hi Hidayat,

 

This one isn't the one in your first post. Is this one still a calculated table? Can you share the file? Mask the sensitive data first.

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi Dale,

 

Sorry about that, could have better phrase it on the original post.

Yes, it is still a calculated table.

 

Below link to file for reference.

 

File Link

 

Best Regards,

Hidayat

 

Hi Hidayat,

 

Try this one please. 

Difference 2 =
VAR currentTimeStamp = [Time_stamp]
VAR lastTimeStamp =
    CALCULATE (
        MAX ( 'Test Table'[Time_stamp] ),
        FILTER ( 'Test Table', 'Test Table'[Time_stamp] < currentTimeStamp )
    )
RETURN
    IF (
        ISBLANK ( lastTimeStamp ),
        0,
        CALCULATE (
            SUM ( [Total Ordered] ),
            ALLEXCEPT ( 'Test Table', 'Test Table'[Time_stamp] )
        )
            - CALCULATE (
                SUM ( 'Test Table'[Total Ordered] ),
                FILTER ( 'Test Table', 'Test Table'[Time_stamp] = lastTimeStamp )
            )
    )

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi Dale,

 

The output is still not correctly calculating.

 

test table.JPG

Regards

Hidayat

Hi Hidayat,

 

Change the aggregation type to others like "Average" or use a measure instead. Please give it a try.

Difference 3 =
VAR lastTimeStamp =
    CALCULATE (
        MAX ( 'Test Table'[Time_stamp] ),
        FILTER (
            ALL ( 'Test Table' ),
            'Test Table'[Time_stamp] < MIN ( 'Test Table'[Time_stamp] )
        )
    )
RETURN
    IF (
        ISBLANK ( lastTimeStamp ),
        0,
        SUM ( [Total Ordered] )
            - CALCULATE (
                SUM ( 'Test Table'[Total Ordered] ),
                FILTER ( ALL ( 'Test Table' ), 'Test Table'[Time_stamp] = lastTimeStamp )
            )
    )

difference_b

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi Dale,

 

The measure "Difference 3" works! 

Capture.JPG

If i were to add column criteria "Season", how do i create a measure to calculate the difference base on this?

 

 

Capture.JPG

 

Regards

Hidayat

Hi Hidayat,

 

Try this one which is more compatible.

Difference 4 =
VAR lastTimeStamp =
    CALCULATE (
        MAX ( 'Test Table'[Time_stamp] ),
        FILTER (
            ALL ( 'Test Table' ),
            'Test Table'[Time_stamp] < MIN ( 'Test Table'[Time_stamp] )
        )
    )
RETURN
    IF (
        ISBLANK ( lastTimeStamp ),
        0,
        SUM ( [Total Ordered] )
            - CALCULATE (
                SUM ( 'Test Table'[Total Ordered] ),
                FILTER (
                    ALL ( 'Test Table'[Time_stamp] ),
                    'Test Table'[Time_stamp] = lastTimeStamp
                )
            )
    )

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors