Forum Discussion

RadoslawM's avatar
RadoslawM
New Member
7 years ago

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

  • Hi,

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

    • RadoslawM's avatar
      RadoslawM
      New Member

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

       

       

       

  • v-juanli-msft's avatar
    v-juanli-msft
    Community Support

    Hi RadoslawM 

    My output is a bit different from yours.

    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.