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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
ilyav
Frequent Visitor

DAX calculation weighted average per category

Hi All,

 

I need help with calculating a weighed average and was not able to find a solution for my use case and would appreaciate any help!

 

I am trying to calculate a margin weighed average per category, here is an example of the data;

ilyav_0-1672906749282.png

 

Category, order, total line sale and margin are given in my dataset and I can calculate the weight = Total line Sale / SUM of all total line sales and Weighed margin = Weight x margin.

 

The problem that I am having now is that I want to create a visual showing the weighted average per category. So the weight column needs to dynamically adjust based on the groupping of the category, meaning that if I want to show 'category a' the 2 lines of the 'weight' need to sum up to 100% and then same for 'category b'.

 

In my example the correct output should be:

Category a weighted average = 39% 

Category b weighted average = 51%

 

Is there a way to DAX it 🙂 ?

Thank you for all any help or pointers!

Ilya

Then I need

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ilyav,

I'd like to suggest you add values function with your category field in the formula and it will auto filter these calculation ranges with current category values.

formula =
CALCULATE (
    CALCULATE ( SUM ( 'Table'[Sales] ), VALUES ( 'Table'[Category] ) )
        / SUM ( 'Table'[Sales] ),
    ALLSELECTED ( 'Table' )
)

Regards,

Xiaoxin Sheng

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @ilyav,

I'd like to suggest you add values function with your category field in the formula and it will auto filter these calculation ranges with current category values.

formula =
CALCULATE (
    CALCULATE ( SUM ( 'Table'[Sales] ), VALUES ( 'Table'[Category] ) )
        / SUM ( 'Table'[Sales] ),
    ALLSELECTED ( 'Table' )
)

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.