Forum Discussion

hama21's avatar
hama21
Icon for Helper I rankHelper I
3 years ago

Difference between date.[month] and date.[year]

Hello everyone,

 

I have a table in my report where I use two measures that are as follows:

 

measure c = DIVIDE((SUM('Table[Value A])*12),SUM('Table'[Value B]))

 

and measure to calculate the average of this measure c

 

average measure c = AVERAGEX ( VALUES ( Calendar[Date].[Month] ), [measure c] )

 

This is the result of my table:

dateteamvalue Avalue Bmeasure Caverage measure C
ago/21A3711,45166193908,10,02680%0,02680%
set/21A2549,991700199410,01800%0,01800%
out/21A19605,06173440583,50,13564%0,13564%
nov/21A24001,52180851849,50,15926%0,15926%
dez/21A14640,11189116781,80,09290%0,09290%
jan/22A5830,26197560129,60,03541%0,03541%
fev/22A16711,02206557220,30,09708%0,09708%
mar/22A16551,37203876476,50,09742%0,09742%
abr/22A14733,25201803932,30,08761%0,08761%
mai/22A17461,04207193959,20,10113%0,10113%
jun/22A31595,37218213661,20,17375%0,17375%
jul/22A76286,54224224552,40,40827%0,40827%
TOTAL 243676,9823390529950,12501%0,11944%

 

The result of my average of measure c in this table, using Calendar[Date].[Month] is 0,11944%. The problem is, when I change to Calendar[Date].[Year] my result is 0,11766%. Could someone please explain to me why I'm having this result change and what would be the correct one?

 

Thank you

5 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    hama21 Well, the reason is that you are taking an average across either 2 rows (Year) or 12 rows (Month). It is also possible that VALUES is returning a blank row and that might also throw some things off. I think that your formula would be much more clear and more flexible if you did not use the auto-time intelligence stuff which has the potential to cause issues as well as use SUMMARIZE or DISTINCT versus VALUES. Seriously, don't use VALUES: https://youtu.be/vOUdKXZpmSc

     

    • hama21's avatar
      hama21
      Icon for Helper I rankHelper I

      How do you recommend my formula? I'm watching the video right now. Thanks for the answer Greg_Deckler 

      • Greg_Deckler's avatar
        Greg_Deckler
        Icon for Community Champion rankCommunity Champion

        hama21 I would need a better sense of your source data to be 100% sure. Is what you posted a good example of how your source data looks? But, I would personally try to do something along the lines of:

        Average Measure =
          VAR __Table =
            SUMMARIZE(
              ADDCOLUMNS(
                'Table',
                "__Month",MONTH('Table'[Date])
              ),
              [__Month],
              "__Measure",[measure c]
            )
        RETURN
          AVERAGEX(__Table,[__Measure])

        A little more verbose because I don't know if you have a Month column already. The advantages of this approach is that you can troubleshoot it by using CONCATENATEX instead of AVERAGEX to inspect your table values within the calculation itself. Also, this method removes any issues that might be caused via table configuration. This form works in a single table data model as well as a star, schema, etc.