Forum Discussion

LeoLi's avatar
LeoLi
Frequent Visitor
1 year ago
Solved

Monthly Average in Matrix

Hello, i am new to Power BI and i am looking for help.   I would like to build a matrix, rows are dates(month and day) and columns are error types.   This is the best i can do but only have month...
  • Anonymous's avatar
    Anonymous
    1 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 Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.