Forum Discussion
Retrospective rolling 6 month average based on given criteria
- 5 years ago
Hi Whitney ,
Try the following formula to create measures:
CurrentMonth = MAX('Slicer Table'[Current Month])relative = VAR MaxDate = [CurrentMonth] VAR MinDate = EOMONTH(MaxDate,-6) + 1 VAR IsWip = IF( MAX('Calendar'[Date]) >= MAX('Table'[Stage 1 start]) && MAX('Calendar'[Date]) <= EOMONTH(MAX('Table'[Stage 2 start]) ,-1), "WIP" ) return IF( MAX('Calendar'[Date]) <= MaxDate && MAX('Calendar'[Date]) >= MinDate, IsWip )Measure = var sum_1 = CALCULATE( SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]), FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],-5),"yyyy mmmm")) ) var sum_2 = CALCULATE( SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]), FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],-4),"yyyy mmmm")) ) var sum_3 = CALCULATE( SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]), FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],-3),"yyyy mmmm")) ) var sum_4 = CALCULATE( SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]), FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],-2),"yyyy mmmm")) ) var sum_5 = CALCULATE( SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]), FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],-1),"yyyy mmmm")) ) var sum_6 = CALCULATE( SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]), FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],0),"yyyy mmmm")) ) var NotNullTotal = IF(sum_1<>BLANK(),1) + IF(sum_2<>BLANK(),1) + IF(sum_3<>BLANK(),1) + IF(sum_4<>BLANK(),1) + IF(sum_5<>BLANK(),1) + IF(sum_6<>BLANK(),1) return DIVIDE( sum_1 + sum_2 + sum_3 + sum_4 + sum_5 + sum_6, NotNullTotal )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
WinnizIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-kkf-msft It was not. I just changed it to a date format to try it returned this error:
"Couldn't load the data for this visual" MdxScript(Model) 8,26) Calculation error in measure 'IDW DimDate'[Measure]: DAX comparison operations do not support comparing values of type Date with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values
Hi Whitney ,
What is the data format of your [CurrentMonth]?
Could you pleasure share screenshots of sample data for the [CurrentMonth] and MonthYear column?
Best Regards,
Winniz
- Whitney5 years ago
Helper II
- v-kkf-msft5 years ago
Community Support
Hi Whitney ,
I guess that the values on the two sides do not match, which caused null value.
Create the following measure to test. If the return value is 1, it means that the expression is correct. If the return value is empty, which means that the values on the two sides are not equal.
Test = CALCULATE( 1, FILTER('IDW DimDate','IDW DimDate'[MonthYear] = FORMAT(EDATE([CurrentMonth],-5),"mmmm yyyy")))Best Regards,
Winniz - Whitney5 years ago
Helper II
v-kkf-msft, I am now getting the below error, both the MonthYear and CurrentMonth formatting is per the screenshots above
"DAX comparison operations do not support comparing values of type Date with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values."
- Whitney5 years ago
Helper II
v-kkf-msftI copied your date expression for Year_Month and everything fell into place and is working now. Thank you very much for the patience and help!
- Whitney5 years ago
Helper II
v-kkf-msft Hi, this is possible stretching the topic of this thread. What I would like to do is add the value of my measure to a stacked bar chart in this format. It doesn't appear possible from what I'm reading unless I make all of my different status' a measure instead of a column value. Do you have a different view on this? Thanks again, Whitney