Forum Discussion
DAX/Formula HELP!
- 6 years ago
Anonymous try this measure
Measure 3 = SUMX ( FILTER ( ALL ( Bal[MONTH] ), Bal[MONTH] <= MAX ( Bal[MONTH] ) ), CALCULATE ( SUM ( Bal[ADDITIONAL] ) ) ) + CALCULATE ( SUM ( Bal[BEG INV] ), Bal[MONTH] = 1 )I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
Anonymous you are pretty much looking for running total
Predicted Ending Inventory =
CALCULATE (
SUM ( Table[Beg Inv] ) +
SUM ( Table[Additionaol ),
FILTER (
ALL ( Table ),
Table[Month] <= MAX ( Table[Month] )
)
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
parry2k thanks for the response. I think this is in the right direction, however, my results were as follows:
| MONTH | BEG INV | ADDITIONAL | END INV | Predicted Ending Inventory | PARRY2K FORMULA |
| 1 | 100 | 100 | 200 | 200 | 200 |
| 2 | 200 | 100 | 300 | 300 | 500 |
| 3 | 300 | 50 | 350 | 350 | 850 |
| 4 | 350 | 200 | 550 | 550 | 1400 |
| 5 | 550 | 50 | 600 | 600 | 2000 |
| 6 | 100 | 700 | 2100 | ||
| 7 | 200 | 900 | 2300 | ||
| 8 | 100 | 1000 | 2400 | ||
| 9 | 100 | 1100 | 2500 | ||
| 10 | 50 | 1150 | 2550 | ||
| 11 | 100 | 1250 | 2650 | ||
| 12 | 50 | 1300 | 2700 |
- camargos886 years ago
Community Champion
Hi Anonymous ,
Create a new blank query and paste this mcode to create a recursive function:
(_table as table, _month as number, _currentMonth as number, _inventoryValue as number) as number =>
let
Source = Table.SelectRows(_table, each [MONTH] = _month),
BEG_INV = if Source[BEG INV]{0} = null or _month > 1 then 0 else Source[BEG INV]{0},
ADDITIONAL = if Source[ADDITIONAL]{0} = null then 0 else Source[ADDITIONAL]{0},
PredictValue = _inventoryValue + ADDITIONAL + BEG_INV,
Result = if _month < _currentMonth then @fn_PredictValues(_table, _month + 1, _currentMonth, PredictValue) else PredictValue
in
ResultUse this mcode to create your base table:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bcxBCsAgDATAr0jOOSSxse1bxP9/Q7GrSMllWYZNaiUlJhXZaSMbVzL05Rme0Zl8sn98oa8jhzs65gVfyuhp/07Tbpgd9gS7NzAVoB+m0dB+w9YB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [MONTH = _t, #"BEG INV" = _t, ADDITIONAL = _t, #"END INV" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"MONTH", Int64.Type}, {"BEG INV", Int64.Type}, {"ADDITIONAL", Int64.Type}, {"END INV", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each fn_PredictValues(#"Changed Type", 1, [MONTH], 0))
in
#"Added Custom"or create a custom column like this:
- parry2k6 years ago
Super User
Anonymous try this measure
Measure 3 = SUMX ( FILTER ( ALL ( Bal[MONTH] ), Bal[MONTH] <= MAX ( Bal[MONTH] ) ), CALCULATE ( SUM ( Bal[ADDITIONAL] ) ) ) + CALCULATE ( SUM ( Bal[BEG INV] ), Bal[MONTH] = 1 )I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
- Anonymous6 years agoNot applicable
Awesome - thank you so much!