Forum Discussion

elmurat's avatar
elmurat
Advocate I
6 months ago
Solved

Cumulative Difference from Another measure

Hello all,   Hope you are all having a great week.   Can you please help me figure out a calculation for the Cumulative Difference from another metric? (Remaining Balance column in my report)   ...
  • v-veshwara-msft's avatar
    v-veshwara-msft
    6 months ago

    Hi elmurat ,

    Thanks for reaching out to Microsoft Fabric Community.

     

    The issue occurs because when multiple rows share the same Battle Date, there is no deterministic row order, which can cause movements to be combined instead of deducted sequentially.

     

    To handle this, I brought NameAccount into the Accounts_Bookings table, sorted the data by NameAccount, Battle Date, and DealName in Power Query, and added a TransactionIndex column to create a stable row order. The running balance then uses this index to ensure row by row subtraction within each account.

    Please find the measure below:

    Remaining Balance = 
    VAR CurrentAccount =
        MAX(Accounts_Bookings[NameAccount])
    
    VAR CurrentIndex =
        MAX(Accounts_Bookings[TransactionIndex])
    
    VAR TotalCash =
        CALCULATE(
            SUM(Accounts_Cash[Total Cash]),
            Accounts_Cash[Account Number] = CurrentAccount
        )
    
    VAR RunningMovement =
        CALCULATE(
            SUM(Accounts_Bookings[Balancito]),
            FILTER(
                ALL(Accounts_Bookings),
                Accounts_Bookings[NameAccount] = CurrentAccount
                    &&
                Accounts_Bookings[TransactionIndex] <= CurrentIndex
            )
        )
    
    RETURN
        TotalCash - RunningMovement

     

    I have attached a screenshot of the output and the PBIX file created using the sample CSV files. Please review and confirm if this aligns with your expected result.