Forum Discussion
How to get an initial 6-weeks sum?
Alert = IF([Closing Inventory]<0,1,0)
This is a measure.
Now i want to get sum of first 6 weeks only.
For example,
For Material Code 1043, the sum should be 2(Initial 6 Weeks sum).
Weeks can be dynamic.
How to get this?
4 Replies
- danextian
Super User
Hi Anonymous
Please elaborate your use case. How to determine the initial six weeks? Based on what logic? What do you mean by weks can be dynamic.
Please provide a sample data as well as the expected result using that data Refer to this post on how to get your question answered quickly: https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/td-p/1447523/jump-to/first-unread-message
- AnonymousNot applicable
Weeks can be dynamic means the starting week could be any week like 23, 24 or 44.
- danextian
Super User
Hi Anonymous
You must use either ALLSELECTED or ALL together with CALCULATE modify the current filter context. Using just MIN is equivalent to the MIN of the current row and not either what are visible or are in the table. Try:
VAR MinWeek = CALCULATE( MIN('HUL (3)'[WeekNo]), ALLSELECTED ( 'HUL (3)' ) ) //min week based on the weeks that are currently visible VAR MinWeek = CALCULATE( MIN('HUL (3)'[WeekNo]), ALL ( 'HUL (3)' ) ) //min week based on the weeks that are in the tableAnd then in your RETURN statement you may or may not wrap the table name after FILTER in ALL or ALLSELECTED depending on the output you want to achieive. Sample below is when using ALL
- AnonymousNot applicableFirst 6 Weeks Sum new =VAR MinWeek = MIN('HUL (3)'[WeekNo]) // Find the minimum week value in the datasetVAR StartingWeek = Max(1, MinWeek) // Ensure the starting week is at least 1VAR EndingWeek = StartingWeek + 5 // Calculate the ending week (starting week + 5)RETURNCALCULATE([Alert],FILTER('HUL (3)','HUL (3)'[WeekNo] >= StartingWeek && 'HUL (3)'[WeekNo] <= EndingWeek))
Used this measure but did not get the correct value.