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
IF
Post Prodigy
Post Prodigy

weighted average and average at the same card/calculation

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.

GoalHighestLowestAverageInvolvedStudentsTotalStudentsGroupClassMonth
240250200240550G1ClassA01.2021
320330280290430G2ClassA01.2021
13014050120720G1ClassB01.2021
80904060340G3ClassB01.2021
3003002002601060G1ClassC01.2021
3003002002601070G4ClassC01.2021
250260200240445G1ClassA02.2021
330340290290535G2ClassA02.2021
13013060130620G1ClassB02.2021
901006070445G3ClassB02.2021
3003002002701050G1ClassC02.2021
3003002002701080G4ClassC02.2021

Actually I have 15 classes, but I just tried to simplify it here. Thanks in advance!

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

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

 

Vera_33_0-1641197857235.png

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]))

View solution in original post

2 REPLIES 2
Vera_33
Resident Rockstar
Resident Rockstar

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

 

Vera_33_0-1641197857235.png

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.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.