Forum Discussion
Iterative calculation
- Anonymous6 years ago
I was going to tell you that you can use a calculated column BUT there is no way to tell powerbi to to run calculations in a certain order (or recursive). So the formula would be fairly complex because you have to do (in your calculated column)
- look for the maximum date available for this inventory id
- determine the stock amount
- iterate through all of the rows from that max date to current date, summing all in, out
so something along the lines of
calcStock=
VAR thisProduct = table[product_id]VAR thisDate = table[inv_date]
VAR maxDate=MAXX(FILTER(table;table[product_id] = thisProduct);table[inv_date])
VAR endStock=MAXX(FILTER(table);table[product_id]=thisProduct && table[inv_date]=maxDate); table[end_day_stock_value])
VAR differential= SUMX(FILTER(Table;table[product_id]=thisProduct && table[inv_date]>=thisDate);table[output]-table[input])
RETURN
endStock+differential(I haven't tested but SHOULD work)
- Anonymous6 years ago
Hi jsteffe
The dax which is written by Anonymous is correct.
One change needs to be done in it for differential
New Stock =VAR thisProduct = 'Table'[product_id]VAR thisDate = 'Table'[inv_date]VAR maxDate=MAXX(FILTER('Table','Table'[product_id] = thisProduct),'Table'[inv_date])VAR endStock=MAXX(FILTER('Table','Table'[product_id]=thisProduct && 'Table'[inv_date]=maxDate),'Table'[Stock])VAR differential= SUMX(FILTER('Table','Table'[product_id]=thisProduct && 'Table'[inv_date]>=thisDate && 'Table'[inv_date]<maxDate),'Table'[output]-'Table'[input])RETURNendStock+differentialThanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar
If I resolve your problem Mark it as a solution and give kudos.
Hi jsteffe
The dax which is written by Anonymous is correct.
One change needs to be done in it for differential
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar
If I resolve your problem Mark it as a solution and give kudos.
- jsteffe6 years ago
Helper III
Thanks a lot for your precise answer : it perfectly works !