Forum Discussion
rolling sum: empty values in groups
- 6 years ago
Okay, seems that I found the solution.
I was using a column value to calculate instead of a measure...
The following measure did what I wanted (except it allready creates a sum for the future 12 weeks)
But this I could solve by filtering the matrix/graph to end at the current week.SUM Last 3M = CALCULATE ( SUM( Sales[WEIGHT] ); FILTER(ALL(Datumtabel[Date]); Datumtabel[Date] <= MAX(Datumtabel[Date]) && DATEADD(Datumtabel[Date];84;DAY) >= MAX(Datumtabel[Date] ) ) )Little side note, it's posible to use MIN instead of MAX, then it shows the sum of the previous 12 weeks instead of current + 11 weeks earlier.
Okay, seems that I found the solution.
I was using a column value to calculate instead of a measure...
The following measure did what I wanted (except it allready creates a sum for the future 12 weeks)
But this I could solve by filtering the matrix/graph to end at the current week.
SUM Last 3M =
CALCULATE (
SUM( Sales[WEIGHT] );
FILTER(ALL(Datumtabel[Date]);
Datumtabel[Date] <= MAX(Datumtabel[Date])
&&
DATEADD(Datumtabel[Date];84;DAY) >= MAX(Datumtabel[Date]
)
)
)
Little side note, it's posible to use MIN instead of MAX, then it shows the sum of the previous 12 weeks instead of current + 11 weeks earlier.
- WillemC6 years agoResolver I
Just one more note. Because of the extra weeks added, which I didn't want, I altered my calendar code and SUM-code.
The datetable code has been altered, so the last day created in this datatable, is the last weekday of the maximum salesdate:
Datumtabel = ADDCOLUMNS( CALENDAR( min(OMZETFEED[LEVDAT]) ; max(OMZETFEED[LEVDAT])-MOD(max(OMZETFEED[LEVDAT])-1;7)+7 ) ; "Jaar";year( [Date] ); "Maandomschr."; FORMAT( [Date] ; "mmm"); "Maandnr" ; month( [Date] ); "Kwartaal-Jaar"; format( [Date] ; "\QQ") & "-" & year([Date]); "ISOWeeknr" ; WEEKNUM([Date];21); "ThisYear" ; if ([Date] >= DATE(YEAR(TODAY());1;1) && [Date] <= TODAY(); 1; 0); "Weekend/werkdag" ; if(WEEKDAY([Date];2)<6;"Werkdag" ; "Weekend"); "Iso Year" ; IF( AND(WEEKNUM([Date];21) < 5;WEEKNUM([Date];2) > 50);year([Date])+1;IF(AND(WEEKNUM([Date];21) > 50;WEEKNUM([Date];2) < 5);year([Date])-1;year([Date]))); "Week-Jaar"; IF( AND(WEEKNUM([Date];21) < 5;WEEKNUM([Date];2) > 50);year([Date])+1;IF(AND(WEEKNUM([Date];21) > 50;WEEKNUM([Date];2) < 5);year([Date])-1;year([Date]))) & if( Weeknum([Date];21)<10;"0";blank())&WEEKNUM([Date];21); "WeekEndDate";[Date]-MOD([Date]-1;7)+7; "WeekStartDate";[Date]-MOD([Date]-1;7)+1 )I've altered the measure to the following code, to get the correct sum values of that week and previous 12 weeks (so 13 weeks in total):
SUM Last 13WKS = CALCULATE ( SUM( OMZETFEED[GEWICHT] ); DATESBETWEEN(Datumtabel[Date];FIRSTDATE(DATEADD(Datumtabel[Date];-84;DAY));LASTDATE(Datumtabel[Date]) ))
This is the result of the start & end period created with this formula:
To create this table create 2 measures:FirstDate = FIRSTDATE(DATEADD(Datumtabel[Date];-84;DAY))and a measure:LastDate = LASTDATE(Datumtabel[Date])