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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
bbbbbunny
New Member

Checking if a % measure is above or below its total calculation

 

Hi all!


I'm super new to PowerBI
I'm trying to create a bubblechart where bubbles will be colored depending on if the value of a measure calculated is below  or above the measure's average/calculation on the total level

 

bbbbbunny_1-1729524722634.png

 

The measure is
Gross margin, % =  [Absolute Margin CY]/[Net Sales CY]
Currently, the bubbles are colored based on a hardcoded value:

 

Margin LEGEND =

IF(
    AND(
        [Sales Change, %] > 0,
        [Gross Margin, %] >= x
    ),
    "Heroes",
    IF(
        AND(
            [Sales Change, %] > 0,
            [Gross Margin, %] < x
        ),
        "Volume Drivers",
        IF(
            AND(
                [Sales Change, %] <= 0,
                [Gross Margin, %] >= x
            ),
            "Profit Drivers",
            IF(
                AND(
                    [Sales Change, %] <= 0,
                    [Gross Margin, %] < x
                ),
                "Bleeders"
            )
        )
    )
)


Where x is the hardcoded value.
I want to change that to a dynamic value that would be similar to the number named "Average margin %" on the graph that changes based on the filters above.

Is there any way to implement that?

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @bbbbbunny ,

Regarding your question, please use the 'ALLSELECTED' function. Simply put, this function clears the filtering effects from the visual and retains the filtering effects of the slicer.

ALLSELECTED function (DAX) - DAX | Microsoft Learn

Replace your 'x' with 'Measure2'

Measure = DIVIDE(SUM('Table'[Gross Margin Abs]),SUM('Table'[Net Sales]))
Measure 2 = CALCULATE(DIVIDE(SUM('Table'[Gross Margin Abs]),SUM('Table'[Net Sales])),ALLSELECTED('Table'))
Measure 3 = IF([Measure] >= [Measure 2] ,"Green","Red")

vzhouwenmsft_0-1729590142608.png

vzhouwenmsft_1-1729590172784.png

vzhouwenmsft_2-1729590209913.png

 

Best Regards,
Wenbin Zhou

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi lbendlin ,thanks for the quick reply, I'll add more.

Hi @bbbbbunny ,
Use the 'GENERATESERIES' function to create a field for slicers

GENERATESERIES function - DAX | Microsoft Learn

Set slicer style to 'less than or equal to'.

Margin LEGEND =
VAR _x = MIN(Field in you slicer)
RETURN
IF(
    AND(
        [Sales Change, %] > 0,
        [Gross Margin, %] >= _x
    ),
    "Heroes",
    IF(
        AND(
            [Sales Change, %] > 0,
            [Gross Margin, %] < _x
        ),
        "Volume Drivers",
        IF(
            AND(
                [Sales Change, %] <= 0,
                [Gross Margin, %] >= _x
            ),
            "Profit Drivers",
            IF(
                AND(
                    [Sales Change, %] <= 0,
                    [Gross Margin, %] < _x
                ),
                "Bleeders"
            )
        )
    )
)

The value of '_x' will dynamically change based on your slicer selection.

 

Best Regards,
Wenbin Zhou

 

Hi!

Thanks a lot for the answer! However, this is not exactly what I'm looking for
I believe I've worded the question incorrectly. What I'm looking for is the way to calculate measure without iterating each row. For example, my measure Gross Margin % is [Gross Margin Abs]/[Net Sales]

I have a table like this

BrandSub-brandProductNet SalesGross Margin Abs
Brand 1Sub-brand 1Product 11000500
Brand 1Sub-brand 1Product 220001100
Brand 1Sub-brand 2Product 335003000
Brand 1Sub-brand 2Product 42500700
Brand 2Sub-brand 3Product 5500300
Brand 2Sub-brand 3Product 615001200
Brand 2Sub-brand 4Product 7750400

 

And I have slicers for Brand, Sub-Brand and Product

 

I want the code to compare each row's (product) Gross Margin % to Gross Margin % calculated for total, filtered by the slicers. For example, if I choose brand 2, I want the code to compare Gross Margin % of each product of Brand 2 to the Gross Margin % of Brand 2 in total

Anonymous
Not applicable

Hi @bbbbbunny ,

Regarding your question, please use the 'ALLSELECTED' function. Simply put, this function clears the filtering effects from the visual and retains the filtering effects of the slicer.

ALLSELECTED function (DAX) - DAX | Microsoft Learn

Replace your 'x' with 'Measure2'

Measure = DIVIDE(SUM('Table'[Gross Margin Abs]),SUM('Table'[Net Sales]))
Measure 2 = CALCULATE(DIVIDE(SUM('Table'[Gross Margin Abs]),SUM('Table'[Net Sales])),ALLSELECTED('Table'))
Measure 3 = IF([Measure] >= [Measure 2] ,"Green","Red")

vzhouwenmsft_0-1729590142608.png

vzhouwenmsft_1-1729590172784.png

vzhouwenmsft_2-1729590209913.png

 

Best Regards,
Wenbin Zhou

 

Thanks a lot! This seems to have worked perfectly

I'm super new to power BI, so this is very-very helpful

lbendlin
Super User
Super User

yes, read about variables in DAX formulas.  Also read about SWITCH  (to make your code look a bit nicer).

lbendlin
Super User
Super User

yes, read about variables in DAX formulas.  Also read about SWITCH  (to make your code look a bit nicer).

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.