Forum Discussion

Powerbiuser77's avatar
Powerbiuser77
Frequent Visitor
6 years ago
Solved

Compare monthly value with a comparative value

Hi Experts, I would like to realize the following project and need help. In general, I want to track error rates. I tried the following steps: Step 1: For each error code should be calculated a com...
  • Anonymous's avatar
    Anonymous
    6 years ago

    HI Powerbiuser77,

    You can try to use below calculate table formula to export summarised result table:

    Table = 
    VAR pyearSummary =
        FILTER (
            GROUPBY (
                ADDCOLUMNS (
                    alarm_history,
                    "Year", YEAR ( [TimeOn Day] ),
                    "Month", MONTH ( [TimeOn Day] )
                ),
                [Alarmcode],
                [PrID],
                [Year],
                [Month],
                "Amount", COUNTX ( CURRENTGROUP (), [Alarmcode] )
            ),
            [Year]
                = YEAR ( TODAY () ) - 1
        )
    VAR mutli_aggreated =
        GROUPBY (
            GROUPBY (
                pyearSummary,
                [Alarmcode],
                [Year],
                [Month],
                "AVG", AVERAGEX ( CURRENTGROUP (), [Amount] )
            ),
            [Alarmcode],
            "TotalAVG", AVERAGEX ( CURRENTGROUP (), [AVG] )
        )
    VAR cyearSummary =
        ADDCOLUMNS (
            GROUPBY (
                FILTER (
                    ADDCOLUMNS (
                        alarm_history,
                        "Year", YEAR ( [TimeOn Day] ),
                        "Month", MONTH ( [TimeOn Day] )
                    ),
                    [Year] = YEAR ( TODAY () )
                        && AND ( [Month] >= MONTH ( TODAY () ), [Month] <= MONTH ( TODAY () ) + 3 )
                ),
                [Alarmcode],
                [PrID],
                [Year],
                [Month],
                "Amount", COUNTX ( CURRENTGROUP (), [Alarmcode] )
            ),
            "Exceed", IF (
                [Amount]
                    > MAXX ( FILTER ( mutli_aggreated, [Alarmcode] = EARLIER ( [Alarmcode] ) ), [TotalAVG] ),
                "Yes",
                "No"
            )
        )
    RETURN
        SUMMARIZE (
            cyearSummary,
            [Alarmcode],
            [PrID],
            [Exceed],
            "FirstExceed", MINX (
                FILTER (
                    cyearSummary,
                    [Alarmcode] = EARLIER ( [Alarmcode] )
                        && [PrID] = EARLIER ( [PrID] )
                        && [Exceed] = "Yes"
                ),
                [Year] * 100 + [Month]
            ),
            "Notice", COUNTROWS (
                FILTER (
                    cyearSummary,
                    [Alarmcode] = EARLIER ( [Alarmcode] )
                        && [PrID] = EARLIER ( [PrID] )
                        && [Exceed] = "Yes"
                )
            ) > 3
        )
    

    Regards,

    Xiaoxin Sheng