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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX Support: Show specific string based on number of filters / or no filters

Dear forum, I hope you can help me once again

I will start by asking the question before showing my examples: 

How does one write an expression to show a specific text string, based on how many filters on a specific dimension level have been applied?  

I am working as controller for a large global organization with several factories and trying to develop a monthly report.
I am stuck on fixing this text window with three different text string measures, showing what factory/factory group has been filtered for. (A factory group is often called a cluster).

I have done a mock-table on what the filter/dimension table structure looks like:

ras_ile_0-1598604076953.png


Based on these three dimension fields that I used as a slicer in my report, I want to write three text string measures to show what Cluster / Sub Cluster / Factory is being filtered - but in a smart way which I'll explain below.

For example: if the slicer is set so that everything - (or, nothing) is filtered, I would like the measures to show this:

Cluster Measure shows: "Cluster - All"
Sub Cluster Measure shows: "Sub Cluster - All"

Factory Measure shows: "Factory - Multiple Selected"

ras_ile_1-1598604214543.png

Similarly, if "Select All" is used, same result.

 

But if we only want to look at Poznan factory, the 3 measures should show the following:

 

ras_ile_3-1598604389559.png

 

But if we look at both Poznan and Madrid factory, I want to be able to show name of both sub-clusters, but the factory name should say "multiple factories". Like below:

 

 

2020-08-28_09-42-02.png

 

 

Any advice on this kind of DAX would be greatly appreciated.
I have thought about SELECTEDVALUE, ISFILTERED and other DAX but realized that I need to combine them with COUNT and I have got lost in the exercise.

/Rasmus 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Found a solution with some googling:


Replaced the ALLSELECTED middle part of the expression with:

COUNTROWS(FILTERS(FactoryTable[Cluster]))=1

Thanks anyway! 

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , Try a measure like

measure = "Cluster : " &
Switch(true(),
not(isfiltered(Table[Cluster])), "All",
countx(allselected(Table),Table[Cluster]) =1, selectedvalue(Table[Cluster]) ,
"Multiple Selected"
)

 

You can add other like this as per need

Anonymous
Not applicable

COUNTX(

ALLSELECTED(FactoryTable),FactoryTable[Cluster]) =1,

SELECTEDVALUE(FactoryTable[Cluster]),
 
 
This part is not working, probably because ALLSELECTED ignores that it is CLUSTER LEVEL.
If I only select a Factory Unit, the filter is correct.

Any idea @amitchandak if there is a different way to count how many have been selected on the higher level?
Anonymous
Not applicable

Found a solution with some googling:


Replaced the ALLSELECTED middle part of the expression with:

COUNTROWS(FILTERS(FactoryTable[Cluster]))=1

Thanks anyway! 
Anonymous
Not applicable

Hi Amit,

Thanks for your reply.

It is almost working - "All" and "Multiple" are going well. But if I just select 1 cluster, I still get "Multiple", which means that the DAX probably does not recognize the part of counting selected = 1. 

I tried adding an "IF" (IF(COUNTX.... =1) but that did not help. What do you think can be the issue? 

Anonymous
Not applicable

ras_ile_0-1598613938719.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.