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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
BIMJ
Frequent Visitor

Dynamic replacement of values in a DAX meaure

Hi Experts

 

The requirement is to replace any value greater than 8 with the average of that particular row excluding the value greater than 8.

Then use that new average to replace the value greater than 8.

 

How to write a dax measure for it (and should be dynamic)?

 

First row is shown with expected result on the right.

Input:

 

CodeBlueGreenRedBlackYellowAverage
A03W 24.193712.6866533.1150433.023828.254807
A024 3.7796171.9713384.0703731.7779282.899814
A1638.747955.0048573.17394811.306122.6677166.180117
A25Q 2.6886761.304879 2.5733942.188983
A62F 4.0134942.167819 1.6115552.597623
A6744 4.4882132.156501 0.3470772.330597
A77S 4.752.387261 54.045754
A795  2.26449 1.4663171.865403

 

Output required

 

Showing only first row

CodeBlueGreenRedBlackYellowAverage
A03W 2.9418392.6866533.1150433.023822.941839

 

Here the green value (which is greater than 8 ) is replaced with the average of other 4 in the row.  Anything above 8 should be replaced by the average of other values in the row

1 ACCEPTED SOLUTION

Hi,

Sorry for not being careful.

Please check the attached file if it suits your requirement.

 

Expected result measure V2: =
VAR _avg =
    AVERAGE ( Data[Value] )
VAR _colorlist =
    FILTER (
        ADDCOLUMNS (
            ALLSELECTED ( Color[Color], Color[Index] ),
            "@value",
                IF (
                    CALCULATE ( SUM ( Data[Value] ) ) > 8,
                    0,
                    CALCULATE ( SUM ( Data[Value] ) )
                )
        ),
        [@value] <> 0
    )
VAR _avgexceptovereight =
    AVERAGEX ( _colorlist, [@value] )
VAR _colorlistreplaceovereight =
    IF ( _avg > 8, _avgexceptovereight, _avg )
RETURN
    IF (
        HASONEVALUE ( Code[Code] ),
        IF (
            HASONEVALUE ( Color[Color] ),
            _colorlistreplaceovereight,
            _avgexceptovereight
        )
    )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

View solution in original post

7 REPLIES 7
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1669127200737.png

 

 

Jihwan_Kim_0-1669127174894.png

 

 

Expected result measure: =
VAR _avg =
    AVERAGE ( Data[Value] )
VAR _colorlist =
    FILTER (
        ADDCOLUMNS (
            ALLSELECTED ( Color[Color], Color[Index] ),
            "@value",
                IF (
                    CALCULATE ( SUM ( Data[Value] ) ) > 8,
                    0,
                    CALCULATE ( SUM ( Data[Value] ) )
                )
        ),
        [@value] <> 0
    )
VAR _avgexceptovereight =
    AVERAGEX ( _colorlist, [@value] )
VAR _colorlistreplaceovereight =
    IF ( _avg > 8, _avgexceptovereight, _avg )
RETURN
    IF (
        HASONEVALUE ( Color[Color] ) && HASONEVALUE ( Code[Code] ),
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( Color[Color] ) = "Average", _avgexceptovereight,
            _colorlistreplaceovereight
        )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

It works but why the total is not showing up?

Hi,

Thank you for your feedback.

In the measure, I purposely made total column and total row blank by adding HASONEVALUE DAX formula. Because I did not know what number to place there.

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Thanks for the prompt reply. It would be great if I can get the total as - 

if any value >8, then the total should be the value used to replace the original value (in this case 2.94) else the original average. 

Hi,

Thank you for your message.

I am not sure if I understood your last question correctly, but is it something like the right side visualization below?

 

Jihwan_Kim_0-1669204337372.png

 

 

Please check the attached pbix file.

Thank you.

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

It is almost as expected! The code A163 should have the total 3.61 

Thank you

Hi,

Sorry for not being careful.

Please check the attached file if it suits your requirement.

 

Expected result measure V2: =
VAR _avg =
    AVERAGE ( Data[Value] )
VAR _colorlist =
    FILTER (
        ADDCOLUMNS (
            ALLSELECTED ( Color[Color], Color[Index] ),
            "@value",
                IF (
                    CALCULATE ( SUM ( Data[Value] ) ) > 8,
                    0,
                    CALCULATE ( SUM ( Data[Value] ) )
                )
        ),
        [@value] <> 0
    )
VAR _avgexceptovereight =
    AVERAGEX ( _colorlist, [@value] )
VAR _colorlistreplaceovereight =
    IF ( _avg > 8, _avgexceptovereight, _avg )
RETURN
    IF (
        HASONEVALUE ( Code[Code] ),
        IF (
            HASONEVALUE ( Color[Color] ),
            _colorlistreplaceovereight,
            _avgexceptovereight
        )
    )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.