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
agalbraith
Helper II
Helper II

Weighted Average for Multiple Variables by One Other Variable

So I have multiple values in columns that all get weighted by one other value to get the weighted average for each. Easily accomplished in SPSS by weighting the data set. Sure I could run the weighted average dax on every single one but that's a bit of a waste of time as I need to do this on multiple tables of data. I need to get all of these values into one bar chart as my end result in the dashboard, which is most easily accomplished by pivoting them into one attribute and one value column. How would I weight all these values by pivoting them though? I tried pivoting just the values and then weight by the other column I need to, but of course the results come out wonky since the rows have all been duplicated with the pivot. Is there a way to accomplish this?

Below is some dummy data to show you what I mean. I need to average all these other columns by weighting by #value

#valueFTPTEducationMilitary
60.850.050.040.06
250.650.050.30
180.50.500
560.950.010.020.02


But I need to unpivot them so that they go in a bar chart. I unpivoted them like this, but this is what doesn't work because then the weighting is off. I also have an ID column. Is there a way to update the formula so that it's only using one each of the weight based on the ID column? That's my thought with what I know of BI dax, I just can't figure out what it should be. This is the dax I was using: DIVIDE (SUMX(Table, Table[#value] * Table[Values]), SUM(Table[#value]))

#valueAttributeValues
6FT0.85
6PT0.05
6Education0.04
6Military0.06
25FT0.65
25PT0.05
25Education0.3
25Military0
18FT0.5
18PT0.5
18Education0
18Military0
56FT0.95
56PT0.01
56Education0.02
56Military0.02
1 ACCEPTED SOLUTION

I went back to my data set and re-did the formula and it still wasn't right with my slicers but I realized it was a bad connection in my web. I was able to fix it! This formula does work even with the long table. Thank you!

View solution in original post

6 REPLIES 6
jdbuchanan71
Super User
Super User

No, this measure works fine also.

Weighted Average 2 = 
DIVIDE(
    SUMX('Table', 'Table'[Values] * 'Table'[#value]),SUM('Table'[#value])
)

I just created the 3 to see the values at each step.

I went back to my data set and re-did the formula and it still wasn't right with my slicers but I realized it was a bad connection in my web. I was able to fix it! This formula does work even with the long table. Thank you!

jdbuchanan71
Super User
Super User

My calculation was done on the unpivoted data and it returns the results I think you want.  Am I not understanding something?

2022-08-09_8-38-19.jpg

I have attached my sample file for you to look at.

 

so I need 3 separate dax formulas to get to the answer I need essentially based on the file. 

jdbuchanan71
Super User
Super User

@agalbraith 

The measure you gave looks right to me for a weighted average calc.  I broke it into 3 just to look at the values.

Weighted Values = SUMX('Table', 'Table'[Values] * 'Table'[#value])
Total Weight = SUM ('Table'[#value])
Weighted Average = DIVIDE([Weighted Values],[Total Weight])

jdbuchanan71_0-1660055324802.png

What are you expecting to see that is different from the output?

Yes those weighted averages at the end are right (just not percentages). I am looking to have one final weighted average for each category. The output bar chart would look like below. I just did the weighted averages in excel and created a chart. This is what I need to accomplish. The formula works for each one individually in the first table I posted but that's a lengthy process. It's not working to produce the correct % when I do it on the pivoted table since those #values are duplicated 4 times.

 

agalbraith_0-1660057376984.png

 

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.