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

Using Calculation Groups with Scatter Plot to control formatting of Measures

Hi All - I was wondering if anyone had experience of using calculation groups with "measure pickers" in the context of a scatter plot;  so the user can pick which measures to show on the x axis and y-axis dynamically.  This works when using what-if parameters; but I have a mix between numerical measures and percentages, so I want to ensure the formatting follows.  I've tried created 2 measure groups for x and y in Tabular Editor as follows: 

 

Create a new calculation group called X-Axis

Add a calculated item for measure 1 number, Expression is selectedmeasure(), format String expression - "0.0"

Add a calculated item for measure 2 percentage, Expression is selectedmeasure(), format string expression  - "0.0%;-0.0%;0.0%"

Create a new measure - "X axis Measure Selected " as :

SWITCH ( SELECTEDVALUE ( 'X-Axis'[Ordinal] ), 
0,[Measure 1 Calc] ,
1, [Measure 2 Calc]
)

(Repeat the steps for Y-Axis)

 

Now when I put the X axis and Y axis measures in a scatter chart, with respective measure picker slicers, no data displays in the chart.  The chart is just blank.  I am guessing this is likely due to some limitations with this method becuase of the mixing of formatting in a single context; I saw a similar reply in this very helpful thread here:  https://community.powerbi.com/t5/Desktop/Dynamic-formatting-of-measures-tutorial

 

I don't plan to show values in the scatter necessarily, so a custom tooltip might be the way to go, but I wanted to see if anyone else has a different approach that might work?  

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @Anonymous 

The most common way I have seen Calculation Groups used for measure selection is to:

  • Create one Calculation Group per measure to be selected.
  • Within each Calculation Group, each Calculation Item corresponds to one underlying measure available for selection.
  • Each Calculation Item completely replaces the selected measure with a specific measure (i.e. doesn't use SELECTEDMEASURE as part of over-ride code itself).

In order to apply this to a scatter plot, where there are two measures to be selected:

  • You would need one Calculation Group per axis (as you've already described).
  • You also would need a dummy measure per axis, say [X-Axis Measure] and [Y-Axis Measure]. These two measures can have any definition you like, and for simplicity I would just use BLANK ().
  • The Calculation Item Expressions would then check if the appropriate dummy measure is selected using ISSELECTEDMEAUSURE, and, if so, return the desired underlying measure. Otherwise, return SELECTEDMEASURE ().
  • The Format String Expressions would be set in a similar way, so that they only return the required format string if the appropriate dummy measure is selected, using ISSELECTEDMEASURE, otherwise return SELECTEDMEASUREFORMATSTRING ().
  • In the scatter plot visual, [X-Axis Measure] and [Y-Axis Measure] are placed on the axes, along with appropriate field(s) in Details or Legend.
  • The two Calculation Groups can be filtered using slicers to select the two measures. The axes will use the format strings defined in the Calculation Items.

 

I have attached a small example PBIX with 5 underlying measures that can be selected for each axis. Here is part of the script for the X-Axis Calculation Group:

 

 

------------------------------
-- Calculation Group: 'X-Axis'
------------------------------
CALCULATIONGROUP 'X-Axis'[X-Axis Measure]

    CALCULATIONITEM "Average Price" = 
        IF (
            ISSELECTEDMEASURE ( [X-Axis Measure] ),
            [Average Price],
            SELECTEDMEASURE ()
        )
        FormatString = 
            VAR FormatString =
                "\$#,0;(\$#,0);\$#,0"
            RETURN
                IF (
                    ISSELECTEDMEASURE ( [X-Axis Measure] ),
                    FormatString,
                    SELECTEDMEASUREFORMATSTRING ()
                )

    CALCULATIONITEM "Average Satisfaction" = 
        IF (
            ISSELECTEDMEASURE ( [X-Axis Measure] ),
            [Average Satisfaction],
            SELECTEDMEASURE ()
        )
        FormatString = 
            VAR FormatString =
                "0.00%;-0.00%;0.00%"
            RETURN
                IF (
                    ISSELECTEDMEASURE ( [X-Axis Measure] ),
                    FormatString,
                    SELECTEDMEASUREFORMATSTRING ()
                )

    // Plus remaining Calculation Items...

 

 

OwenAuger_0-1649215595661.png

Hopefully this is close to what you were trying to be do, but please post back if needed.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

4 REPLIES 4
OwenAuger
Super User
Super User

Hi @Anonymous 

The most common way I have seen Calculation Groups used for measure selection is to:

  • Create one Calculation Group per measure to be selected.
  • Within each Calculation Group, each Calculation Item corresponds to one underlying measure available for selection.
  • Each Calculation Item completely replaces the selected measure with a specific measure (i.e. doesn't use SELECTEDMEASURE as part of over-ride code itself).

In order to apply this to a scatter plot, where there are two measures to be selected:

  • You would need one Calculation Group per axis (as you've already described).
  • You also would need a dummy measure per axis, say [X-Axis Measure] and [Y-Axis Measure]. These two measures can have any definition you like, and for simplicity I would just use BLANK ().
  • The Calculation Item Expressions would then check if the appropriate dummy measure is selected using ISSELECTEDMEAUSURE, and, if so, return the desired underlying measure. Otherwise, return SELECTEDMEASURE ().
  • The Format String Expressions would be set in a similar way, so that they only return the required format string if the appropriate dummy measure is selected, using ISSELECTEDMEASURE, otherwise return SELECTEDMEASUREFORMATSTRING ().
  • In the scatter plot visual, [X-Axis Measure] and [Y-Axis Measure] are placed on the axes, along with appropriate field(s) in Details or Legend.
  • The two Calculation Groups can be filtered using slicers to select the two measures. The axes will use the format strings defined in the Calculation Items.

 

I have attached a small example PBIX with 5 underlying measures that can be selected for each axis. Here is part of the script for the X-Axis Calculation Group:

 

 

------------------------------
-- Calculation Group: 'X-Axis'
------------------------------
CALCULATIONGROUP 'X-Axis'[X-Axis Measure]

    CALCULATIONITEM "Average Price" = 
        IF (
            ISSELECTEDMEASURE ( [X-Axis Measure] ),
            [Average Price],
            SELECTEDMEASURE ()
        )
        FormatString = 
            VAR FormatString =
                "\$#,0;(\$#,0);\$#,0"
            RETURN
                IF (
                    ISSELECTEDMEASURE ( [X-Axis Measure] ),
                    FormatString,
                    SELECTEDMEASUREFORMATSTRING ()
                )

    CALCULATIONITEM "Average Satisfaction" = 
        IF (
            ISSELECTEDMEASURE ( [X-Axis Measure] ),
            [Average Satisfaction],
            SELECTEDMEASURE ()
        )
        FormatString = 
            VAR FormatString =
                "0.00%;-0.00%;0.00%"
            RETURN
                IF (
                    ISSELECTEDMEASURE ( [X-Axis Measure] ),
                    FormatString,
                    SELECTEDMEASUREFORMATSTRING ()
                )

    // Plus remaining Calculation Items...

 

 

OwenAuger_0-1649215595661.png

Hopefully this is close to what you were trying to be do, but please post back if needed.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn
Anonymous
Not applicable

Thanks Owen, this is EXACTLY what I need, and works within my own datset. Thanks for taking the time to explain, and providing a sample! 

amitchandak
Super User
Super User

@Anonymous , the measure does not seem like a calculation group. In the calculation group, you have the option to give a format string

https://www.sqlbi.com/blog/marco/2020/07/15/creating-calculation-groups-in-power-bi-desktop/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

The measure isn't a calculation group.  I'm formatting the individual calculation items in  the calculation group, which is then governed by the Ordinal in the switch calculation. This works in the context of say, wanting to switch the measure on a bar chart.   

NicEdmonds_0-1649060947018.png

 

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.