DAX remaining sum after deductions

vipett

New Member
Joined
May 6, 2021
Messages
17
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I'm trying to look at our demand going forward and the current stock levels.
For example, if we in January have 20 in demand and 50 in stock, then nothing needs to go to step two (breakdown to components) and we would have 30 left in stock. If the demand is 40 in february, then the net need (to step 2) would be 10 (30 in stock - 40 in demand), and every month after that, the entire demand would go to step two.

Important: The table I am using in Power BI is crossjoined via formulas, thus I can't do anything in PowerQuery. (If I do the crossjoin in Powerquery, the size becomes larger than 2gb for some reason..)

See sample file here what I currently do in Excel:
 

Attachments

  • Untitled.png
    Untitled.png
    25.3 KB · Views: 22

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I have tried this so far, but it basically just takes the demand - stock and doesn't consider if the stock was consumed previously..

RemainingDemand =
VAR CurrentMonth = Table[Month]
VAR CurrentProduct = Table[UnifiedItemNumber]
VAR PreviousStock =
CALCULATE (
SUM ( Table[Stock] ),
FILTER (
Table,
Table[UnifiedItemNumber] = CurrentProduct
&& Table[Month]= MAXX (
FILTER (
Table,
Table[UnifiedItemNumber] = CurrentProduct
&& Table[Month] < CurrentMonth
),
Table[Month]
)
)
)
VAR CurrentDemand = Table[Total]
RETURN
IF (
PreviousStock >= CurrentDemand,
0,
IF ( PreviousStock = 0, CurrentDemand, CurrentDemand - PreviousStock )
)
 
Upvote 0

Forum statistics

Threads
1,225,024
Messages
6,182,431
Members
453,112
Latest member
laky131

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top