Forum Discussion
Cumulative Difference from Another measure
- 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 - RunningMovementI 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.
Hi,
Share the download link of the 3 input excel files as well.
hi Ashish,
Here is the link to the csv files:
https://drive.google.com/file/d/138sVSdxrzkoiqZ4vP7Y_thBEtPWK4ZCL/view?usp=sharing
- Ashish_Mathur6 months agoSuper User
Hi,
PBI file attached.
- elmurat6 months agoAdvocate I
Thanks Ashish. Do you how to make the Remaining balance reflect each DealName?
When I have 2 same Dates, for two different DealNames, the 2 Movement amounts are being added up and subtracted from the Total Money, so the Remaining Balance is the same for two DealNames. I feel like the DealName should be included in the logic somewhere. Thanks!
- Ashish_Mathur6 months agoSuper User
You are welcome. In the file that i shared with you, create this scenarion and share the download link of the PBI file. Also, show the expected result there.