Forum Discussion
Monthly Average in Matrix
- Anonymous1 year ago
Hi LeoLi ,
Here I suggest you to create a DimDate Table and a Level Table contains Days and "Sum", "Average" in it.
DimDate = ADDCOLUMNS(CALENDARAUTO(),"YearMonth",YEAR([Date]) * 100 + MONTH([Date]),"MonthNum",MONTH([Date]),"Month",FORMAT([Date],"MMMM"),"Day",DAY([Date]),"DayKey",FORMAT(DAY([Date]),"00"))Level2 = UNION(DISTINCT(SELECTCOLUMNS(DimDate,"Value",FORMAT([Day],"00"))),{"Sum","Average"})Relationship:
Measures:
Count Error = CALCULATE(COUNT('Table'[Error Type]))Measure 2 = VAR _DAY = CALCULATE(COUNT('Table'[Error Type]),FILTER(DimDate,DimDate[DayKey] = MAX(Level2[Value]))) VAR _SUM = [Count Error] VAR _AVERAGE = AVERAGEX(VALUES(DimDate[Day]),[Count Error]) RETURN SWITCH(MAX(Level2[Value]),"SUM", _SUM,"Average", _AVERAGE,_DAY)Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi LeoLi ,
Here I suggest you to create a DimDate Table and a Level Table contains Days and "Sum", "Average" in it.
DimDate = ADDCOLUMNS(CALENDARAUTO(),"YearMonth",YEAR([Date]) * 100 + MONTH([Date]),"MonthNum",MONTH([Date]),"Month",FORMAT([Date],"MMMM"),"Day",DAY([Date]),"DayKey",FORMAT(DAY([Date]),"00"))Level2 =
UNION(DISTINCT(SELECTCOLUMNS(DimDate,"Value",FORMAT([Day],"00"))),{"Sum","Average"})
Relationship:
Measures:
Count Error = CALCULATE(COUNT('Table'[Error Type]))Measure 2 =
VAR _DAY = CALCULATE(COUNT('Table'[Error Type]),FILTER(DimDate,DimDate[DayKey] = MAX(Level2[Value])))
VAR _SUM = [Count Error]
VAR _AVERAGE = AVERAGEX(VALUES(DimDate[Day]),[Count Error])
RETURN
SWITCH(MAX(Level2[Value]),"SUM", _SUM,"Average", _AVERAGE,_DAY)
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- LeoLi1 year agoFrequent Visitor
That really works! Thank you so much!
- LeoLi1 year agoFrequent Visitor
Hi Anonymous , Thank you for your previous answer that really helps me a lot.
However, i have a further question about the average. I would like to put weekends data in the dashboard but i want them only counted in sum, not in average. To better describe this case, pls see in screenshot. for Aug's data, I would like to divide sum only by 2 days (not including aug 31st). So the highlighted 115 would be 346/2=173. And also for Aug 30th, there is one error not showing up so the average of that error becomes 9/1=1, which i hope it would be 9/2=4.5.
The way to decide if the date should be included when counting the average could be the total error numbers of that day is higher than 20.
Would you please help me with above again.
Thank you in advance!