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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
RadoslawM
New Member

Subtracting rows

Hi folks,

 

I'm new here and quite new to power BI.

 

I have two tables:

1. Items with purchase date & Quantity

ItemNoPurchaseDateQuantityIndex
85420/03/2019322
85430/04/20194803
85407/05/2019164
85427/01/20192031
34620/05/201932
34623/07/201923
34622/01/201911
34608/08/201914

 

2. Sales forecast

ItemNoForecast
854350
3462

 

I would like to add Balance column to my table 1, that will subtract forecast from quantity, starting with the oldest PurchaseDate. My desired outcome is this:

ItemNoPurchaseDateQuantityIndexBalance
85420/03/20193220
85430/04/20194803365
85407/05/201916416
85427/01/201920310
34620/05/2019322
34623/07/2019232
34622/01/2019110
34608/08/2019141

How can I achieve this with simple measures?

 

Thanks in advance.

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @RadoslawM 

My output is a bit different from yours.

Capture2.JPG

Create columns

clc_quan = CALCULATE(SUM('Table 1'[Quantity]),FILTER(ALLEXCEPT('Table 1','Table 1'[ItemNo]),'Table 1'[PurchaseDate]<=EARLIER('Table 1'[PurchaseDate])))

clc_quan = CALCULATE(SUM('Table 1'[Quantity]),FILTER(ALLEXCEPT('Table 1','Table 1'[ItemNo]),'Table 1'[PurchaseDate]<=EARLIER('Table 1'[PurchaseDate])))

Column = IF([clc_for]=BLANK(),0,[clc_quan]-[clc_for])

Please tell me if i misunderstand anything.

 

Best Regards
Maggie

 

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

Ashish_Mathur
Super User
Super User

Hi,

How have you arrived at the numbers in the Balance column?  What is the logic?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

SUM of Quantity minus Forecast = Balance is my logic, but it would only work if the table was grouped by item. 

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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