Forum Discussion

SamTailor's avatar
SamTailor
Helper I
10 years ago
Solved

Monthly Average Grand Total calculation - Help needed

Hi!

 

I'm new in Power BI and can't figure out how to do a tricky thing with Grand Total of Average

I have a table with Monthly averages, but grand totalin Power BI shows me SUM of these averages.

 

 

 

What i want him to shows me in Grand Total is Year Average basing on number of days.

 This is how i do it in Excel

 

Plese Help, maybe there is some formula to solve this ?

  • Hi,

     

    In this scenario, if you include “Direction” column into your table visual, definitely your measure will be sliced by “direction”. This is how DAX works. So you need to group on month in your calculation.

     

    AverageMeasure = CALCULATE(AVERAGEA(Direction[AV Plan]),ALLEXCEPT(Direction,Direction[Month #]))

     

     

    As to show Year Average basing on number of days in your top table of this case(I assume it’s called “Direction2”), You can create a following measure:

     

    avgMeasure = CALCULATE(sumx(Direction2, Direction2[monthDay] * Direction2[Average]) / sumx(Direction2, Direction2[monthDay]))

     

     

    Best Regards

    Alex

     

     

     

11 Replies

  • AlexChen's avatar
    AlexChen
    Microsoft Employee

    Hi,

     

    In this scenario, if you include “Direction” column into your table visual, definitely your measure will be sliced by “direction”. This is how DAX works. So you need to group on month in your calculation.

     

    AverageMeasure = CALCULATE(AVERAGEA(Direction[AV Plan]),ALLEXCEPT(Direction,Direction[Month #]))

     

     

    As to show Year Average basing on number of days in your top table of this case(I assume it’s called “Direction2”), You can create a following measure:

     

    avgMeasure = CALCULATE(sumx(Direction2, Direction2[monthDay] * Direction2[Average]) / sumx(Direction2, Direction2[monthDay]))

     

     

    Best Regards

    Alex

     

     

     

    • SamTailor's avatar
      SamTailor
      Helper I

      Hi ALex,

       

      Thanks for your reply. I still can't make it work the way U do. I created the measure for Direction2 and this is what i got

       

       

       

       

      The problem is that Number of days is 186 in my case - Power BI sums it((( How have you created a column "monthDay"? - i believe its the key queestion to solve the problem....

      • AlexChen's avatar
        AlexChen
        Microsoft Employee

        Hi,

         

        You can go to powerbi desktop.  choose "monthDay" column.

         

         

        choose "Default Summarization: Do Not Summarize".

         

         

        do the samething for column "month".

         

        Now remove your table visual on "Direction2" then create a new one.

         

        Best Regards

        Alex

         

         

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Couple things you could do. In your table settings, click the drop down arrow next to "Average Plan" and choose "Average" instead of "Sum".

     

     

    You could also create a Measure like: 

     

    MyAverage = AVERAGE(Averages[Average Plan])

    Use that in your table instead.

     

     

     

     

    • SamTailor's avatar
      SamTailor
      Helper I

      I'm afraid this method gives a little different result - 66 885 instead of 66 920

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        Correct, this is averaging all of the averages, which will return a different result than taking the SUM total and dividing by the total number of days. Lots of rounding issues going on. I can't figure out why your numbers are different than mine in Excel (see below).

         

        So, basically, I'm not sure of your source data, but if you have something like this:

         

        MonthDaysAverage
        3170425
        2960138
        3159234
        3058987
        3158371
        3061831
        3163388
        3163795
        3069316
        3174747
        3078325
        3184066

         

        Then create a calculated column:

         

        MonthAverageNumber = [MonthDays] * [Average]

        Then create a measure like:

         

        MyMeasure = SUM([MonthAverageNumber]) / SUM(MonthDays)