Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and a 50 percent discount on exams.
Get startedEarn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi,
I want to develop a measure to calculate average and weighted average at the same measure. I am using 3 slicers for selection (Month, Group, and Class). If I select class slicer, then the result should be calculated based on the average. If I don't select the class the result should be calculated based on the weighted average, but class C should not be considered in the calculation.
If I don't select anything in the Class slicer, then it should calculate the weighted average based on the "average" value per class and the number of students. However, Class C should not be considered in the calculation. For example; for the selection of January 2021 in the month slicer and not select anything in Class slicer, it should provide:
ClassA: (240+290)/2=265 and ClassB: (120+60)/2=90 and the weighted average should be:
((265*80)+(90*60))/(80+60) =190
If I select ClassA, then it should provide the result 265, which is the average, not the weighted average.
This is the data.
Goal | Highest | Lowest | Average | InvolvedStudents | TotalStudents | Group | Class | Month |
240 | 250 | 200 | 240 | 5 | 50 | G1 | ClassA | 01.2021 |
320 | 330 | 280 | 290 | 4 | 30 | G2 | ClassA | 01.2021 |
130 | 140 | 50 | 120 | 7 | 20 | G1 | ClassB | 01.2021 |
80 | 90 | 40 | 60 | 3 | 40 | G3 | ClassB | 01.2021 |
300 | 300 | 200 | 260 | 10 | 60 | G1 | ClassC | 01.2021 |
300 | 300 | 200 | 260 | 10 | 70 | G4 | ClassC | 01.2021 |
250 | 260 | 200 | 240 | 4 | 45 | G1 | ClassA | 02.2021 |
330 | 340 | 290 | 290 | 5 | 35 | G2 | ClassA | 02.2021 |
130 | 130 | 60 | 130 | 6 | 20 | G1 | ClassB | 02.2021 |
90 | 100 | 60 | 70 | 4 | 45 | G3 | ClassB | 02.2021 |
300 | 300 | 200 | 270 | 10 | 50 | G1 | ClassC | 02.2021 |
300 | 300 | 200 | 270 | 10 | 80 | G4 | ClassC | 02.2021 |
Actually I have 15 classes, but I just tried to simplify it here. Thanks in advance!
Solved! Go to Solution.
Hi @IF
Here is one way, but I am not sure weighted avg should use the original avg column in the table or not...it comes the test = 182.14 instead of 190
test =
VAR T1=FILTER(Table1,Table1[Class]<>"ClassC")
RETURN
IF(ISFILTERED(Table1[Class]),AVERAGE(Table1[Average]),
SUMX(T1,Table1[Average]*Table1[TotalStudents])/SUMX(T1,[TotalStudents]))
test1 =
VAR T1=GROUPBY(Table1,Table1[Class],"Avg",AVERAGEX(CURRENTGROUP(),[Average]),
"TotalStu",SUMX(CURRENTGROUP(),Table1[TotalStudents]))
VAR T2=FILTER(T1,Table1[Class]<>"ClassC")
RETURN
IF(ISFILTERED(Table1[Class]),AVERAGE(Table1[Average]),
SUMX(T2,[Avg]*[TotalStu])/SUMX(T2,[TotalStu]))
Hi @IF
Here is one way, but I am not sure weighted avg should use the original avg column in the table or not...it comes the test = 182.14 instead of 190
test =
VAR T1=FILTER(Table1,Table1[Class]<>"ClassC")
RETURN
IF(ISFILTERED(Table1[Class]),AVERAGE(Table1[Average]),
SUMX(T1,Table1[Average]*Table1[TotalStudents])/SUMX(T1,[TotalStudents]))
test1 =
VAR T1=GROUPBY(Table1,Table1[Class],"Avg",AVERAGEX(CURRENTGROUP(),[Average]),
"TotalStu",SUMX(CURRENTGROUP(),Table1[TotalStudents]))
VAR T2=FILTER(T1,Table1[Class]<>"ClassC")
RETURN
IF(ISFILTERED(Table1[Class]),AVERAGE(Table1[Average]),
SUMX(T2,[Avg]*[TotalStu])/SUMX(T2,[TotalStu]))
Perfect! thanks, the test1 works as I wanted.