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
CJonsson
Frequent Visitor

Dynamic categories (category changed/recalculated based on slicer choices)

Hi!

 

We have a dataset with Z-scores for different indexes. What we want to do is create an average per country, and then split these averages into four different categories according to the below split. 

This category should be dynamic, to reflect the average and subsequent category for only the selected indexes. 

SWITCH (
        TRUE(),
        WeightedIndexISO >= 0.675, "1",
        WeightedIndexISO >= -0.6745, "2",
        WeightedIndexISO >= -1.349, "3",
        WeightedIndexISO < -1.349, "4",
        "ERROR"

 

Our isssue is that we are not able to make the category dynamic. It just shows one single bucket based on the average for all indexes and countries, no matter the selection in slicers. 

 

For example. When having all indexes selected Mexico will have an average Z score of -0.50 and end up in bucket 2. 

 

CJonsson_0-1706708656019.png

 

But when selecting only index OCI Criminal Markets the weighted Z score is -2.48 and it should end up in bucket 3. However this doesn't work, it still says bucket 2.

 

CJonsson_1-1706708868154.png

 

Does anyone know how to create a measure for the buckets that is updated accordingly when selecting specific indexes?

 

I have added a table with sample data as I cannot attach a file in this post. 

 

ISO_masterCountryNameValue
FINFinlandWWF Biodiversity Risk-1.63984192031225e-02
FINFinlandCorruption Perception Index2.35900749904752
FINFinlandWGI Control of Corruption1.69796487970888
FINFinlandWGI Government Effectiveness1.6050756606592
FINFinlandWGI Political Stability No Violence1.021483657793
FINFinlandWGI Regulatory Quality1.61987738724371
FINFinlandWGI Rule of Law1.71856732295757
FINFinlandWGI Voice and Accountability1.66894695148963
FINFinlandOrganised Crime Index Criminality avg.1.53129131803688
FINFinlandOrganised Crime Index Resilience avg.2.327153193201
FINFinlandUN Gender Development Index0.632950692278289
FINFinlandUN Gender Inequality Index1.57974687551886
FINFinlandUN Human Development Index1.45641292235099
FINFinlandUN Inequality-adjusted Human Development Index1.54243873110673
FINFinlandUN Planetary pressures-adjusted Human Development Index0.847762965542295
FINFinlandOrganised Crime Index Criminal Markets avg.1.22544881018327
INDIndiaWWF Biodiversity Risk-1.28684437009771
INDIndiaCorruption Perception Index-0.159569411848747
INDIndiaWGI Control of Corruption-0.196085634193209
INDIndiaWGI Government Effectiveness0.453578519938367
INDIndiaWGI Political Stability No Violence-0.876123125262151
INDIndiaWGI Regulatory Quality3.14281131669952e-02
INDIndiaWGI Rule of Law0.177864201703347
INDIndiaWGI Voice and Accountability-2.51527244560662e-02
INDIndiaOrganised Crime Index Criminality avg.-0.536460573897385
INDIndiaOrganised Crime Index Resilience avg.0.368851031097534
INDIndiaUN Gender Development Index-1.49129358229469
INDIndiaUN Gender Inequality Index-0.738810852199814
INDIndiaUN Human Development Index-0.581279383253759
INDIndiaUN Inequality-adjusted Human Development Index-0.652279470432859
INDIndiaUN Planetary pressures-adjusted Human Development Index-0.246591439427658
INDIndiaOrganised Crime Index Criminal Markets avg.-1.39278917669132
MEXMexicoWWF Biodiversity Risk-0.611919958684961
MEXMexicoCorruption Perception Index-0.641850096913989
MEXMexicoWGI Control of Corruption-1.11882816035763
MEXMexicoWGI Government Effectiveness-0.260025268024007
MEXMexicoWGI Political Stability No Violence-0.973436296987146
MEXMexicoWGI Regulatory Quality-0.114449942919375
MEXMexicoWGI Rule of Law-1.0060444856019
MEXMexicoWGI Voice and Accountability-0.27428512617622
MEXMexicoOrganised Crime Index Criminality avg.-1.89505567978921
MEXMexicoOrganised Crime Index Resilience avg.-0.36932517330907
MEXMexicoUN Gender Development Index0.632950692278289
MEXMexicoUN Gender Inequality Index0.179480064030121
MEXMexicoUN Human Development Index0.248399894272606
MEXMexicoUN Inequality-adjusted Human Development Index0.119838258301552
MEXMexicoUN Planetary pressures-adjusted Human Development Index0.605569777557141
MEXMexicoOrganised Crime Index Criminal Markets avg.-2.48435778346411
ZAFSouth AfricaWWF Biodiversity Risk-7.59505731513069e-02
ZAFSouth AfricaCorruption Perception Index1.19081650633412e-03
ZAFSouth AfricaWGI Control of Corruption-0.179897147002125
ZAFSouth AfricaWGI Government Effectiveness-6.54060292779549e-02
ZAFSouth AfricaWGI Political Stability No Violence-1.03831170108231
ZAFSouth AfricaWGI Regulatory Quality-0.19549324915312
ZAFSouth AfricaWGI Rule of Law0.145428302339864
ZAFSouth AfricaWGI Voice and Accountability0.639200128213896
ZAFSouth AfricaOrganised Crime Index Criminality avg.-1.60392815709811
ZAFSouth AfricaOrganised Crime Index Resilience avg.0.496964256655704
ZAFSouth AfricaUN Gender Development Index-4.98421102630261e-02
ZAFSouth AfricaUN Gender Inequality Index-0.307569261705094
ZAFSouth AfricaUN Human Development Index-5.02846456368857e-02
ZAFSouth AfricaUN Inequality-adjusted Human Development Index-0.673433380809144
ZAFSouth AfricaUN Planetary pressures-adjusted Human Development Index0.103243165439786
ZAFSouth AfricaOrganised Crime Index Criminal Markets avg.-1.52255607399998

 

1 ACCEPTED SOLUTION
123abc
Community Champion
Community Champion

To create dynamic categories based on slicer choices in Power BI, you need to use measures that respond to the current filter context. In your case, you want to categorize countries based on the average Z-score of selected indexes. You can achieve this using a DAX measure that calculates the average Z-score for the selected indexes and then assigns the category accordingly.

Here's a general approach to achieve this:

  1. Calculate the Average Z-score for Selected Indexes: You need to create a measure that calculates the average Z-score for the selected indexes.

  2. Assign Categories Dynamically: Use a SWITCH statement in another measure to assign categories dynamically based on the average Z-score.

Here's how you can implement these steps:

Step 1: Calculate the Average Z-score for Selected Indexes

 

AverageZScore =
VAR SelectedIndexes = VALUES('YourIndexColumn')
RETURN
AVERAGEX(
FILTER(
'YourTable',
'YourIndexColumn' IN SelectedIndexes
),
[Value]
)

 

Step 2: Assign Categories Dynamically

 

DynamicCategory =
VAR AvgZScore = [AverageZScore]
RETURN
SWITCH (
TRUE(),
AvgZScore >= 0.675, "1",
AvgZScore >= -0.6745, "2",
AvgZScore >= -1.349, "3",
AvgZScore < -1.349, "4",
"ERROR"
)

 

Notes:

  • Replace 'YourIndexColumn' with the appropriate column containing index names.
  • Replace 'YourTable' with the name of your table.
  • Replace '[Value]' with the column name that contains the Z-scores.
  • Ensure that the slicer visuals are set up to filter the appropriate columns in your data model.

These measures should dynamically respond to slicer selections, recalculating the average Z-score and assigning categories accordingly. Make sure your visuals are configured to react to these measures appropriately.

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

View solution in original post

4 REPLIES 4
CJonsson
Frequent Visitor

Thank you! That worked and the category is dynamic now. 

 

One follow-up question. I would like to have a table showing the different categories and how many countries place within each category (still dynamic based on which indexes I choose). However, when placing the DynamicCategory in a table it will just show one category - calculating the average for all countries combined.

 

Is it possible to group this by country?

 

CJonsson_0-1706715831401.png

 

123abc
Community Champion
Community Champion

Certainly! If you want to display the count of countries within each category dynamically based on the selected indexes, you can create another measure to count the distinct countries within each category. Here's how you can do it:

Step 1: Create a Measure to Count Countries by Category

 

Countries by Category =
COUNTROWS(
FILTER(
VALUES('YourTableName'[Country]),
[Dynamic Category] = SELECTEDVALUE('YourTableName'[Dynamic Category])
)
)

 

Step 2: Build the Table

Now, you can create a table visual with two columns:

  • Category: Drag the Dynamic Category measure to this column.
  • Country Count: Drag the Countries by Category measure to this column.

Ensure that the table visual is not applying any additional filters or slicers that might interfere with the dynamic calculation of the measures.

This table will dynamically display the count of countries within each category based on the selected indexes. It should update as you change the selections in your slicers or filters.

Adjust the column names and formatting as per your preferences. This setup allows for a dynamic display of country counts within each category.

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

I am not quite getting this to work. 

 

I cannot select the DynamicCategory as SELECTEDVALUE. Don't know if that is because it is a measure?

123abc
Community Champion
Community Champion

To create dynamic categories based on slicer choices in Power BI, you need to use measures that respond to the current filter context. In your case, you want to categorize countries based on the average Z-score of selected indexes. You can achieve this using a DAX measure that calculates the average Z-score for the selected indexes and then assigns the category accordingly.

Here's a general approach to achieve this:

  1. Calculate the Average Z-score for Selected Indexes: You need to create a measure that calculates the average Z-score for the selected indexes.

  2. Assign Categories Dynamically: Use a SWITCH statement in another measure to assign categories dynamically based on the average Z-score.

Here's how you can implement these steps:

Step 1: Calculate the Average Z-score for Selected Indexes

 

AverageZScore =
VAR SelectedIndexes = VALUES('YourIndexColumn')
RETURN
AVERAGEX(
FILTER(
'YourTable',
'YourIndexColumn' IN SelectedIndexes
),
[Value]
)

 

Step 2: Assign Categories Dynamically

 

DynamicCategory =
VAR AvgZScore = [AverageZScore]
RETURN
SWITCH (
TRUE(),
AvgZScore >= 0.675, "1",
AvgZScore >= -0.6745, "2",
AvgZScore >= -1.349, "3",
AvgZScore < -1.349, "4",
"ERROR"
)

 

Notes:

  • Replace 'YourIndexColumn' with the appropriate column containing index names.
  • Replace 'YourTable' with the name of your table.
  • Replace '[Value]' with the column name that contains the Z-scores.
  • Ensure that the slicer visuals are set up to filter the appropriate columns in your data model.

These measures should dynamically respond to slicer selections, recalculating the average Z-score and assigning categories accordingly. Make sure your visuals are configured to react to these measures appropriately.

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

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.

Top Solution Authors