Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Calculate average by week base on a date

Hi everybody,   I am trying to calculate an average by week based on a date. My data table is about alerts from servers Some of these servers have been patched, and for theses one I have a patch ...
  • AlexisOlson's avatar
    4 years ago

    Something like this?

     

    WeeklyAvgBeforePatch =
    AVERAGEX (
        ADDCOLUMNS (
            VALUES ( Alerts[WeekNumber] ),
            "@BeforeCount", CALCULATE ( COUNTROWS ( Alerts ), Alerts[BeforePatch] = 1 )
        ),
        [@BeforeCount]
    )
    
    WeeklyAvgAfterPatch =
    AVERAGEX (
        ADDCOLUMNS (
            VALUES ( Alerts[WeekNumber] ),
            "@AfterCount", CALCULATE ( COUNTROWS ( Alerts ), Alerts[BeforePatch] = 0 )
        ),
        [@AfterCount]
    )