Forum Discussion

fedeleu's avatar
fedeleu
Frequent Visitor
4 years ago
Solved

Average

Hi!

I have a model with the next table (this is a small sample of a much larger base)

 

NameYearMonthReviewCountWeight
Name120211A1410
Name120211A1160
Name120213A2530
Name120219A325
Name220218B1110
Name2202110B2110

 

 

For each "Name", I must first group by "Review" and calculate the difference between 100 and the sum of its "Weight".

So, I create two measures

 

aux = SUMX([Table],Table[Count]*Table[Weight])
 
aux2 =
VAR CUENTA=100-[aux]
VAR CUENTA2=IF(CUENTA<0,0,CUENTA)
RETURN
IF([aux]<1,BLANK(),CUENTA2)
 
 

I get the following results, which were as expected

 

NameReviewaux2
Name1A10
Name1A20
Name1A390
Name2B190
Name2B290

 

OK, now is when I have a problem.

 

For each "Name", I must calculate the average of "aux2"

 

I created the following measure, but I'm not getting the expected results.

 

avg= AVERAGEX(NC_Peso_KPI,[aux2])
 
Nameavgavg_expected
Name147,530
Name29090

 

Can someone help me find the error?

 

Regards,

Federico.

  • The reason it's giving this is that you are averaging at the table row granularity. That is, averaging these values:

     

    To fix this, you need to average over the appropriate granularity:

    avg = AVERAGEX ( SUMMARIZE ( Peso, Peso[Name], Peso[Review] ), [aux2] )

3 Replies

  • The reason it's giving this is that you are averaging at the table row granularity. That is, averaging these values:

     

    To fix this, you need to average over the appropriate granularity:

    avg = AVERAGEX ( SUMMARIZE ( Peso, Peso[Name], Peso[Review] ), [aux2] )

  • fedeleu's avatar
    fedeleu
    Frequent Visitor

    Thanks for your help AlexisOlson,
    Can I bother you with another question?
    I have 2 date slicers (one for month and one for year), both single-select.
    Since the calculation of "avg" I must do it 12 months back, I adapted the measure as follows (there is a column "Date" that I did not name before)

    Table [Date] is linked with Calendar [Date]

     

    avg = CALCULATE(AVERAGEX (SUMMARIZE ( Table, Table[Name], Table[Review],Table[Date] ), [aux2] ),DATESBETWEEN(Calendar[Date],NEXTDAY(SAMEPERIODLASTYEAR(LASTDATE(Calendar[Date]))),LASTDATE(Calendar[Date])))

     

    But doesnt work.

    I get, at least in a small sample that I made, the same values ​​as without having made the change to your formula.

     

    Any suggestion?

    Thanks you

    • AlexisOlson's avatar
      AlexisOlson
      Super User

      I can't quite tell what's going on from this description. You may want to create a new post with more detail and, ideally, link to a sample file others can follow along with.