Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Max_Kloosterman
Frequent Visitor

Calculating a measure that gives me the "right" average ...

Hi,

 

Earlier I received help form @LivioLanzo to resolve my question on how to structure my data. That worked However ... a new question came up that I cannot seem to resolve. It is about calculating a measure that does NOT do a weighted average 🙂

 

I want to use this measure in a visualisation so that it shows: (in table form)

respondentquestioncategoryquestionscoreaveragebyquestionaveragebyquestioncategoryaveargebyrespondent
resp1cat1cat1.15554,5
resp1cat1cat1.25554,5
resp1cat1cat1.35554,5
resp1cat2cat2.15544,5
resp1cat2cat2.23344,5

 

Regardless of the number of questions in a category, each respondent will need to get an average based on the average over all categories. To calculate the total, each category should have one vote. In the example above. The average should be 4,5 as in the table above. I however keep getting 4,6 (the weighted average)

 

My key problem seems to be how to create a function that iterates not over each row but over a new/filtered? table that contains only the average for a category. Is that at all possible, to use DAX to create a virtual table that contains a subset of rows and columns from the original table as well as the values from a measure?

 

I even find it difficult to do this in excel so thinking through this problem proves to be harder than I thought it would be - even though the concept seems so straightforward.

 

Kind regards,

 

Max

 

Earlier (resolved) post https://community.powerbi.com/t5/Desktop/Average-of-answer-by-question-with-multiple-value-types/m-p...

1 ACCEPTED SOLUTION

I thought I solved this question myself - until it turned out I didn't

the path I tried: is to use the formula suggested (the allselected (values version ) to calculate the average for each category and then using that formula inside another calculation that divides the sum of those averages for a respondent by the distinctcount of categories for a respondent. IT came up with the correct average in the total row in the bottom of the table, however I couldn't get it to work on the rows of the table.

Will remain interested in any working and preferably a very elegant approach. 

Kind regards,

Max

DAX I ended up trying that got me close but not quite there:

Average Scores := calculate ( average( table[score], filter ( table, table[score] <>0))

Average by respondent := averagex ( values ( questioncategory) , [Average Scores]))

Kind regards,
Max

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @Max_Kloosterman ,

You can add use allexcept to choose which fields filtered formula calculation.

Sample:

 

Count Measure =
CALCULATE (
    AVERAGE ( Table[Score] ),
    ALLSELECTED ( Table ),
    VALUES ( Table[ColumnName] )
)

Count Measure2 =
CALCULATE ( AVERAGE ( Table[Score] ), ALLEXCEPT ( Table, Table[ColumnName] ) )

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft 

 

I've tested this solution and it still gives me 4,6 and not 4,5... this is proving to be a hard one. Any other idea's?

 

To understand it better I've looked at a couple of lessons on The ALL, ALLSELECTED and ALLEXCEPT filters today and am learning more and more. Thanks for that. 

 

One additional question / complication: In my real table respondents are able to score 0 to indicate that they did not want to answer that question. I am trying to figure out where to filter out those values. i.e. where do I insert a filter that ensures only values are considered that fullfil the condition Table[score]<>0? For the interim I have dealt with this by changing all 0 scores to null upon import of the data.

 

Kind regards,

 

Max

I thought I solved this question myself - until it turned out I didn't

the path I tried: is to use the formula suggested (the allselected (values version ) to calculate the average for each category and then using that formula inside another calculation that divides the sum of those averages for a respondent by the distinctcount of categories for a respondent. IT came up with the correct average in the total row in the bottom of the table, however I couldn't get it to work on the rows of the table.

Will remain interested in any working and preferably a very elegant approach.&nbsp;

Kind regards,

Max

DAX I ended up trying that got me close but not quite there:

Average Scores := calculate ( average( table[score], filter ( table, table[score] <>0))

Average by respondent := averagex ( values ( questioncategory) , [Average Scores]))

Kind regards,
Max

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.