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
Anonymous
Not applicable

Weighted average of 2 attributes with values in the same value-column

Hello,

my dataTable looks like this:

Knipsel.PNG

 

I want to calculate the weighted day-average of  Analyse.Gcv[kWh/m³] based on the hour-values of attribute ML.Energy[kWh].

 

It is possible with a calculated column, but is there a way to do this more efficient with a DAX formula? 

maybe withe AVERAGEX, buth I don't know how to itterate in the same column. 

 

Thanks in advance!

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Please refer to below measures:

Measure_1 =
CALCULATE (
    AVERAGE ( Test_8[Value] ),
    FILTER ( ALLSELECTED ( Test_8 ), Test_8[Attribute] = "A" )
)

Measure_2 =
VAR A_value =
    IF (
        SELECTEDVALUE ( Test_8[Attribute] ) = "B",
        CALCULATE (
            SUM ( Test_8[Value] ),
            FILTER (
                ALL ( Test_8 ),
                Test_8[Attribute] = "A"
                    && Test_8[Date] = MAX ( Test_8[Date] )
            )
        )
    )
VAR _product =
    SUM ( Test_8[Value] ) * A_value
RETURN
    _product

Measure_3 =  SUMX(ALLSELECTED(Test_8),[Measure_2])

Measure_4 =
[Measure_3]
    / CALCULATE (
        SUM ( Test_8[Value] ),
        FILTER ( ALLSELECTED ( Test_8 ), Test_8[Attribute] = "B" )
    )

1.PNG

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
yaman123
Post Partisan
Post Partisan

Hey, how can this be done with more than 2 attributes such as attribute A, B, C, D, E etc

 

Thanks

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

 

Not very clear about your desired result, please illustrate "weighted average" with examples.

How to Get Your Question Answered Quickly

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi, 

I give another example (with calculation) out of excel:

DateAttributeValue
1/janA5
2/janA0
3/janA63
4/janA2
5/janA1
6/janA44
1/janB23
2/janB25
3/janB26
4/janB20
5/janB12
6/janB20
AvG A=AVERAGE(C2:C7)19,1667
Weighted average A=SUMPRODUCT(C2:C7;C8:C13)/SUM(C8:C13)21,3095

 

How can I achieve the same calculation in Power BI without unpivot the attribute-column.

Hi @Anonymous ,

 

Please refer to below measures:

Measure_1 =
CALCULATE (
    AVERAGE ( Test_8[Value] ),
    FILTER ( ALLSELECTED ( Test_8 ), Test_8[Attribute] = "A" )
)

Measure_2 =
VAR A_value =
    IF (
        SELECTEDVALUE ( Test_8[Attribute] ) = "B",
        CALCULATE (
            SUM ( Test_8[Value] ),
            FILTER (
                ALL ( Test_8 ),
                Test_8[Attribute] = "A"
                    && Test_8[Date] = MAX ( Test_8[Date] )
            )
        )
    )
VAR _product =
    SUM ( Test_8[Value] ) * A_value
RETURN
    _product

Measure_3 =  SUMX(ALLSELECTED(Test_8),[Measure_2])

Measure_4 =
[Measure_3]
    / CALCULATE (
        SUM ( Test_8[Value] ),
        FILTER ( ALLSELECTED ( Test_8 ), Test_8[Attribute] = "B" )
    )

1.PNG

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.