Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago

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

  • v-jiascu-msft's avatar
    v-jiascu-msft
    Icon for Microsoft Employee rankMicrosoft 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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Dale,

       

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

       

      My data is repeated on rows instead of column.

       

       

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

       

      Regards

      Hidayat

      • v-jiascu-msft's avatar
        v-jiascu-msft
        Icon for Microsoft Employee rankMicrosoft Employee

        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