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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Thigs
Helper IV
Helper IV

Weighted average but filter?

I've look at the other weighted average posts and still a little confused so hoping for some help. I have a large data set with SKUs, a metric called pallet factor (how much of that particular SKU fits on a pallet, ex - 54 cases), and a quantity shipped for the month (ex - 32 cases of this SKU shipped in December). 

 

I need to create a weighted average using the amount of times shipped x the pallet factor, so I'm weighting the pallet factor. 

 

BUT I need to make it able to be filtered. So if I select the clothes department, it changes the weights to only the clothes department. If it's the pet department, only the pet department, and if its both, then both are included in the weights. 

Here is my formula so far - 

Weighted PF = 

VAR _Table = summarize('Order Data','Order Data'[SKU], "Quantity New", sum('Order Data'[Quantity]), "PF", AVERAGE('Pallet Factor'[PF]))

RETURN
SUMX(_Table, ([Quantity New] * [PF])/sum([Quantity New]))

It is just returning "NaN", so clearly I'm doing something wrong. Are you able to use two different tables in a summarize formula? I've never tried that before. The tables are indirectly related through a fact table. 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Thigs , try like

Weighted PF =
VAR _Table = summarize('Order Data','Order Data'[SKU], "Quantity New", sum('Order Data'[Quantity]), "PF", AVERAGE('Pallet Factor'[PF]))
RETURN
divide( SUMX(_Table, [Quantity New] * [PF]),SUMX(_Table,[Quantity New]))

 

or

 

Weighted PF =
VAR _Table = summarize('Order Data','Order Data'[SKU], "Quantity New", sum('Order Data'[Quantity]), "PF", AVERAGE('Pallet Factor'[PF]))
RETURN
SUMX(_Table, divide([Quantity New] * [PF],[Quantity New]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Thigs , try like

Weighted PF =
VAR _Table = summarize('Order Data','Order Data'[SKU], "Quantity New", sum('Order Data'[Quantity]), "PF", AVERAGE('Pallet Factor'[PF]))
RETURN
divide( SUMX(_Table, [Quantity New] * [PF]),SUMX(_Table,[Quantity New]))

 

or

 

Weighted PF =
VAR _Table = summarize('Order Data','Order Data'[SKU], "Quantity New", sum('Order Data'[Quantity]), "PF", AVERAGE('Pallet Factor'[PF]))
RETURN
SUMX(_Table, divide([Quantity New] * [PF],[Quantity New]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Worked beautifully, thanks a bunch!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.