Forum Discussion
Cumulative calculation with Calculated column
- 1 year ago
Hi arun0386 ,
Now that you're able to retrieve week 34, this code should definitely work:Step.01.DrillDown = VAR _LastWeek = CALCULATE( MAX('Table'[Week]), FILTER( ALL('Table'), NOT(ISBLANK('Table'[Inventory]))) ) RETURN IF( // checks to see if I have an inventory week SELECTEDVALUE('Table'[Week]) > _LastWeek, // if not, let's "fill down" and return the value for the last week CALCULATE(SUM('Table'[Inventory]), KEEPFILTERS('Table'[Week] = _LastWeek), ALL('Table')), // if there is, return me normal inventory value SUM('Table'[Inventory]) )Sharing the pbix that I used for your example so you can take a look at it as a reference.
window-function-previous-row.pbix (link 1)window-function-previous-row.pbix (link 2)
Hi hnguy71 , Thanks for responding. Step 2 & 3 worked like a charm. But something is not working in Step 1. it is not filling up the following weeks like your screenshot. mystery!!!
- hnguy711 year agoSuper User
Hi arun0386
Glad it's halfway working for ya! We'll need to debug as to understand why the first measure is not filling down. Let's modify the first measure twice and see what we return.
Adjust to this expression and share me the screenshot of the result:Step.01.DrillDown = VAR _LastWeek = CALCULATE(MAX('Table'[Week]), 'Table'[Inventory] <> BLANK(), ALL('Table')) RETURN _LastWeek & " | " & SELECTEDVALUE('Table'[Week])
Then, adjust the expression again and share me the screenshot of the next result:Step.01.DrillDown = VAR _LastWeek = CALCULATE(MAX('Table'[Week]), 'Table'[Inventory] <> BLANK(), ALL('Table')) RETURN IF( // checks to see if I have an inventory week SELECTEDVALUE('Table'[Week]) > _LastWeek, // if not, let's "fill down" and return the value for the last week 100, // if there is, return me normal inventory value SUM('Table'[Inventory]) )