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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
inesj
Frequent Visitor

Multiply average by value in related table

Hello!

 

I have a survey divided in different sections, each containing multiple questions. The average score for a section is based on the average score per question, multiplied by the question's weight. Here is what my tables look like:

inesj_1-1713259563286.png

 

Table 1 is related to Table 2 by the Section column, and Table 2 is related to Table 3 by the Question # column.

 

The desired output would be as follows:

inesj_0-1713259543394.png

 

Note that this should be done through measures rather than calculated columns, as I want the user to be able to apply some filters (e.g., filter out some respondents). 

 

This does not look like such a complex request, but for some reason nothing I have tried so far seems to be working...

I hope you can help!

 

Thank you. 

 

 

 

 

 

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @inesj ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create measures. 

Average = CALCULATE(AVERAGE('Table3'[Score]),FILTER(ALLSELECTED('Table3'),[Question #]=MAX('Table2'[Question #])))
Avg = [Average] * MAX('Table2'[Weight]) 
Avg2 = 

SUMX(SUMMARIZE(ALLSELECTED('Table2'),[Section],[Question #],"a",[Avg]),[a])
Weighted Avg = CALCULATE([Avg2],FILTER('Table1',MAX('Table1'[Section]) in VALUES('Table1'[Section]) && MAX('Table2'[Question #]) in VALUES('Table2'[Question #])))

(3) Then the result is as follows.

vtangjiemsft_0-1713514028178.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

3 REPLIES 3
v-tangjie-msft
Community Support
Community Support

Hi @inesj ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create measures. 

Average = CALCULATE(AVERAGE('Table3'[Score]),FILTER(ALLSELECTED('Table3'),[Question #]=MAX('Table2'[Question #])))
Avg = [Average] * MAX('Table2'[Weight]) 
Avg2 = 

SUMX(SUMMARIZE(ALLSELECTED('Table2'),[Section],[Question #],"a",[Avg]),[a])
Weighted Avg = CALCULATE([Avg2],FILTER('Table1',MAX('Table1'[Section]) in VALUES('Table1'[Section]) && MAX('Table2'[Question #]) in VALUES('Table2'[Question #])))

(3) Then the result is as follows.

vtangjiemsft_0-1713514028178.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

AnalyticsWizard
Solution Supplier
Solution Supplier

@inesj 

 

1. Ensure you have relationships set between your tables: Table 1 and Table 2 on 'Section', and Table 2 and Table 3 on 'Question #'.

 

2. Create a measure to calculate the weighted score for each question. This measure will multiply the score of each question by its weight.

Weighted Score = SUMX(Table3, Table3[Score] * RELATED(Table2[Weight]))

 

3. Create another measure to calculate the total weighted score per section. This measure will sum the weighted scores for each section.

 

Total Weighted Score by Section = CALCULATE([Weighted Score], ALL(Table3[Question #]))

 

4. Now, create a measure to calculate the sum of weights per section, which is needed to find the average.

 

Total Weight Per Section = CALCULATE(SUM(Table2[Weight]), ALL(Table3[Question #]))

 

5. Finally, create the measure to calculate the weighted average score per section. This measure will divide the total weighted score by the sum of weights per section.

 

Weighted Average Score = [Total Weighted Score by Section] / [Total Weight Per Section]

 

Make sure to replace the table and column names with the actual names used in your model.

 

When you use these measures in your report, you can apply filters, and the calculations will adjust accordingly because of the use of `ALL` which removes the filter context from the specified columns, allowing you to calculate the total regardless of any filters applied.

 

If this post helps, please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

Hello @AnalyticsWizard,

 

Thank you so much for the quick reply!

Based on your advice, I have created the following measures:

 

inesj_0-1713261368686.pnginesj_1-1713261383127.png

Unfortunately, the results I am seeing are not as expected:

 

inesj_3-1713261493239.png

 

The value for D1.1 should be 2.00 ((3+1)/2), and the total for "D1 - Delivery Management" should be 3.00 (2.00*0.5 + 4*0.5). 

 

Is there anything I have overlooked?

 

Thank you! 🙂 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.