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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
NonoP
New Member

Weighted average in DAX with wrong total

Hello,

 

I am doing a double weighted average:

I have for every month, the associated number of days per month, one column category, the associated power of the category, the value I want to average. Here is an example of the table:

NonoP_0-1736940025847.png

 

The thing is I want to weight the value according to the number of days in a month and the "Power" of the associated category.

To do that I have a quite simple measure, the table is named "Plant":

 

 

Av_Tot_Plant_TEST =
CALCULATE (
    SUMX ( Plant, Plant[Availability] * Plant[Nb_jours] * Plant[Max_Power (MW)] )
        / ( SUMX ( Plant, Plant[Nb_jours] * Plant[Max_Power (MW)] ) )
)

 

 

 

The result works well if I chek the results per category, or if I check as a total per month.

However I know the global total to be wrong. The global is the final value if I take into account all months and all categories.

I believe it is because one of the category is present only on a couple of months and thus the total power varies through the year.

 

How could I tweak the measure to get the correct Total?

 

Thanks in advance

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@NonoP , Try using 

 

DAX
Av_Tot_Plant_TEST =
AVERAGEX (
VALUES ( Plant[Month] ),
CALCULATE (
SUMX ( Plant, Plant[Availability] * Plant[Nb_jours] * Plant[Max_Power (MW)] )
/ SUMX ( Plant, Plant[Nb_jours] * Plant[Max_Power (MW)] )
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @NonoP 

 

If you want your measure to be evaluted for each month then summed up at the total level.

Av_Tot_Plant_TEST =
VAR _tbl = 
    ADDCOLUMNS (
        SUMMARIZE('datetable', 'datetable'[month]), -- Create a summarized table by month
        "@avg", 
        DIVIDE( -- Calculate the average availability
            SUMX(
                Plant,
                Plant[Availability] * Plant[Nb_jours] * Plant[Max_Power (MW)] -- Numerator: Weighted availability
            ),
            SUMX(
                Plant,
                Plant[Nb_jours] * Plant[Max_Power (MW)] -- Denominator: Total days multiplied by max power
            )
        )
    )
RETURN
    SUMX(_tbl, [@avg]) -- Sum the calculated averages for each month

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
bhanu_gautam
Super User
Super User

@NonoP , Try using 

 

DAX
Av_Tot_Plant_TEST =
AVERAGEX (
VALUES ( Plant[Month] ),
CALCULATE (
SUMX ( Plant, Plant[Availability] * Plant[Nb_jours] * Plant[Max_Power (MW)] )
/ SUMX ( Plant, Plant[Nb_jours] * Plant[Max_Power (MW)] )
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks you!!

johnt75
Super User
Super User

Try

Av_Tot_Plant_TEST =
SUMX (
    VALUES ( Plant[mois] ),
    CALCULATE (
        SUMX ( Plant, Plant[Availability] * Plant[Nb_jours] * Plant[Max_Power (MW)] )
            / ( SUMX ( Plant, Plant[Nb_jours] * Plant[Max_Power (MW)] ) )
    )
)

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors