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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ashraf_K
Frequent Visitor

Running Difference per day and name

Below is a sample data that is being used.

The requirement is to calculate the remaining for each row by substracting it from the previous line.

Basically for  10 Oct it is easily calculated, however for 18 OCT we should take 3,445,900 - 1,000,00 as we had 2 purchased on 18 Oct

Is there a way to achieve this on power BI?

 

Vessel NamePurchase dateRequiredPurchasedremaining
RT 0110-Oct-22 3,645,900    200,000  3,445,900
RT 0118-Oct-22     500,000 
RT 0119-Oct-22  1,400,000 
RT 0118-Oct-22     500,000 
RT 0129-Mar-22     400,000 
RT 0124-Nov-22     645,000 
RU 0516-Mar-233,459,2501,500,0001,959,250
RU 0503-Apr-23 200,000 
RU 0503-Apr-23 400,000 
RU 0504-Apr-23 500,000 
MV 0511-Apr-23 100,000 
MV 0511-Apr-23 1,000,000 
1 ACCEPTED SOLUTION

Then, something like on the screenshot below. The table visual allows sorting by multiple columns if you hold SHIFT key.

barritown_0-1696934163257.png

In plain text:

Remaining = 
VAR CurDate = [Purchase date]
VAR CurVessel = [Vessel Name]
VAR _tbl = FILTER ( Data, [Vessel Name] = CurVessel && [Purchase date] <= CurDate )
RETURN SUMX ( FILTER ( Data, [Vessel Name] = CurVessel ) , [Required] ) - SUMX ( _tbl, [Purchased] )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

View solution in original post

4 REPLIES 4
barritown
Super User
Super User

Hi @ashraf_K,

I'd solve your task with a calculation column like this. The question is how to treat the date 29.03.2022, which appears somewhere in the middle.

barritown_0-1696933150818.png

In plain text:

Remaining = 
VAR CurDate = [Purchase date]
VAR CurVessel = [Vessel Name]
VAR _tbl = FILTER ( Data, [Vessel Name] = CurVessel && [Purchase date] <= CurDate )
RETURN SUMX ( _tbl, [Required] ) - SUMX ( _tbl, [Purchased] )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

Ideally it should be sorted by purchase date so that we can show how the purchase is progressing through time

Then, something like on the screenshot below. The table visual allows sorting by multiple columns if you hold SHIFT key.

barritown_0-1696934163257.png

In plain text:

Remaining = 
VAR CurDate = [Purchase date]
VAR CurVessel = [Vessel Name]
VAR _tbl = FILTER ( Data, [Vessel Name] = CurVessel && [Purchase date] <= CurDate )
RETURN SUMX ( FILTER ( Data, [Vessel Name] = CurVessel ) , [Required] ) - SUMX ( _tbl, [Purchased] )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Yes, that does solve the issues.

 

Thank you!

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.