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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Read39487
Regular Visitor

Dynamic text based on filter selection

Hi all,

 

I'm looking for a method to display a text dynamically based on filter selection.

I have checked different methods suggested in other articles but none works as expected so far.

 

The table I have has 2 columns like below:

 

AGroup 1
BGroup 1
CGroup 1
DGroup 2
EGroup 3

 

I would like to create a text that would show for A, B, C as

(1) "Group 1" when all options in Group 1 are selected (A,B,C are all selected)

(2) A when in Group 1 only A  is selected. B when in Group 1 only B is selected. C when in Group 1 only C is selected. 

(3) A/B when in Group 1 only A and B are selected, etc

 

It would be as below presented as a table

ProductWhen A, B, and C are all selectedWhen only A is selectedWhen only A and B are selected
AGroup 1AA/B
BGroup 1AA/B
CGroup 1AA/B
DGroup 2Group 2Group 2
EGroup 3Group 3Group 3

 

I'm mainly looking for method that would work for 1st and 2nd situation (when A and B and C are all selected or only A is selected).

 

I have tried a formula shared in another article as below but it shows only blank no matter what options I selected.

VAR _count = CALCULATE(COUNT('Table'[Product]), FILTER('Table', [Product] IN VALUES('Table'[Product])))
RETURN
IF(_count = 1, MAX([Product]), "Multiple")
4 ACCEPTED SOLUTIONS
rohit1991
Super User
Super User

Hii @Read39487 

 

To return dynamic text based on the selected products, you first need to detect how many items from Group 1 are selected. Once you know the count, you can build the text accordingly. A simple pattern is:

SelectedText :=
VAR L = VALUES('Table'[Product])
VAR C = COUNTROWS(L)
RETURN
SWITCH(
    TRUE(),
    C = 3, "Group 1",
    C = 1, MAX('Table'[Product]),
    C = 2, CONCATENATEX(L, [Product], "/"),
    "Multiple"
)

This returns “Group 1” when A,B,C are all selected, returns A, B, or C when only one is selected, and returns A/B, A/C, etc. when two are selected. This approach reliably handles all three scenarios you described.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

MFelix
Super User
Super User

Hi @Read39487 ,

 

Try the following code:

Dynamic Text =	SWITCH(
		TRUE(),
		COUNTROWS('Table') = COUNTROWS(FILTER(
			ALL('Table'),
			'Table'[Group] = MAX('Table'[Group])
		)), SELECTEDVALUE('Table'[Group]),
		COUNTROWS(SUMMARIZE(
			'Table',
			'Table'[Group]
		)) = 1 &&
		COUNTROWS('Table') <= COUNTROWS(FILTER(
			ALL('Table'),
			'Table'[Group] = MAX('Table'[Group])
		)), CONCATENATEX(
			'Table',
			'Table'[Product],
			"/"
		),
		COUNTROWS('Table') = 1, SELECTEDVALUE('Table'[Product]),
		"Multiple Values"
	)

MFelix_0-1764762272362.png

MFelix_1-1764762281668.png

MFelix_2-1764762287496.png

MFelix_3-1764762293566.png

 

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

danextian
Super User
Super User

Hi @Read39487 

Try this:

text = 
-- Get the currently selected product (if only one is selected)
VAR _prodSelected = SELECTEDVALUE(Tbl[Product])

-- Get the currently selected group (if only one is selected)
VAR _group = SELECTEDVALUE(Tbl[Group])

-- Get all products in the current filter context
VAR _productsSelected = VALUES(Tbl[Product])

-- Get all products that belong to Group 1, ignoring current filters
VAR _group1Products = 
    CALCULATETABLE(
        VALUES(Tbl[Product]), 
        FILTER(ALL(Tbl), Tbl[Group] = "Group 1")
    )

-- Check if all selected products are exactly Group 1 products
VAR _allGroup1Selected = 
    VAR _selectedVsGroup = COUNTROWS(EXCEPT(_group1Products, _productsSelected))   -- Items in Group 1 not selected
    VAR _groupVsSelected = COUNTROWS(EXCEPT(_productsSelected, _group1Products))   -- Items selected not in Group 1
    RETURN ISBLANK(_selectedVsGroup) && ISBLANK(_groupVsSelected)                  -- True if selection matches all of Group 1 exactly

-- Precompute concatenated product names for multiple selections
VAR twoProducts = CONCATENATEX(_productsSelected, [Product], "/")

-- Check if a subset of Group 1 products is selected
VAR _subsetGroup1Selected = 
    COUNTROWS(INTERSECT(_productsSelected, _group1Products)) = COUNTROWS(_productsSelected) &&
    COUNTROWS(_productsSelected) < COUNTROWS(_group1Products)

-- Determine the final result based on selection logic
VAR _result  = 
SWITCH(
    TRUE(),
    -- If a single product D or E is selected, return its group
    _prodSelected IN {"D", "E"}, _group,

    -- If all Group 1 products are selected and no other products, return "Group 1"
    _allGroup1Selected, "Group 1",

    -- If a subset of Group 1 products is selected, return the concatenated product names
    _subsetGroup1Selected, twoProducts,

    -- If any other single product is selected, return that product
    NOT _prodSelected IN {"D", "E"}, _prodSelected
)

-- Return the result
RETURN
_result

danextian_0-1764764087870.gif

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

Kedar_Pande
Super User
Super User

@Read39487 

 

Dynamic Selection =
VAR SelectedItems = VALUES('Table'[Product])
VAR ItemCount = COUNTROWS(SelectedItems)
VAR GroupName = MAX('Table'[Group]) // Assumes Group column exists
RETURN
SWITCH(
TRUE(),
ItemCount = 1, SELECTEDVALUE('Table'[Product]), // Single item: "A"
ItemCount = 3 && HASONEVALUE('Table'[Group]), GroupName, // All Group 1: "Group 1"
CONCATENATEX(SelectedItems, 'Table'[Product], "/", "") // Multiple: "A/B"
)

 

If this answer helped, please click Kudos or Accept as Solution.
-Kedar
LinkedIn: https://www.linkedin.com/in/kedar-pande

View solution in original post

6 REPLIES 6
Kedar_Pande
Super User
Super User

@Read39487 

 

Dynamic Selection =
VAR SelectedItems = VALUES('Table'[Product])
VAR ItemCount = COUNTROWS(SelectedItems)
VAR GroupName = MAX('Table'[Group]) // Assumes Group column exists
RETURN
SWITCH(
TRUE(),
ItemCount = 1, SELECTEDVALUE('Table'[Product]), // Single item: "A"
ItemCount = 3 && HASONEVALUE('Table'[Group]), GroupName, // All Group 1: "Group 1"
CONCATENATEX(SelectedItems, 'Table'[Product], "/", "") // Multiple: "A/B"
)

 

If this answer helped, please click Kudos or Accept as Solution.
-Kedar
LinkedIn: https://www.linkedin.com/in/kedar-pande

danextian
Super User
Super User

Hi @Read39487 

Try this:

text = 
-- Get the currently selected product (if only one is selected)
VAR _prodSelected = SELECTEDVALUE(Tbl[Product])

-- Get the currently selected group (if only one is selected)
VAR _group = SELECTEDVALUE(Tbl[Group])

-- Get all products in the current filter context
VAR _productsSelected = VALUES(Tbl[Product])

-- Get all products that belong to Group 1, ignoring current filters
VAR _group1Products = 
    CALCULATETABLE(
        VALUES(Tbl[Product]), 
        FILTER(ALL(Tbl), Tbl[Group] = "Group 1")
    )

-- Check if all selected products are exactly Group 1 products
VAR _allGroup1Selected = 
    VAR _selectedVsGroup = COUNTROWS(EXCEPT(_group1Products, _productsSelected))   -- Items in Group 1 not selected
    VAR _groupVsSelected = COUNTROWS(EXCEPT(_productsSelected, _group1Products))   -- Items selected not in Group 1
    RETURN ISBLANK(_selectedVsGroup) && ISBLANK(_groupVsSelected)                  -- True if selection matches all of Group 1 exactly

-- Precompute concatenated product names for multiple selections
VAR twoProducts = CONCATENATEX(_productsSelected, [Product], "/")

-- Check if a subset of Group 1 products is selected
VAR _subsetGroup1Selected = 
    COUNTROWS(INTERSECT(_productsSelected, _group1Products)) = COUNTROWS(_productsSelected) &&
    COUNTROWS(_productsSelected) < COUNTROWS(_group1Products)

-- Determine the final result based on selection logic
VAR _result  = 
SWITCH(
    TRUE(),
    -- If a single product D or E is selected, return its group
    _prodSelected IN {"D", "E"}, _group,

    -- If all Group 1 products are selected and no other products, return "Group 1"
    _allGroup1Selected, "Group 1",

    -- If a subset of Group 1 products is selected, return the concatenated product names
    _subsetGroup1Selected, twoProducts,

    -- If any other single product is selected, return that product
    NOT _prodSelected IN {"D", "E"}, _prodSelected
)

-- Return the result
RETURN
_result

danextian_0-1764764087870.gif

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
grazitti_sapna
Super User
Super User

Hi @Read39487,

 

Attached is the pbix with working solution.

 

🌟 I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
💡 Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
🎖 As a proud SuperUser and Microsoft Partner, we’re here to empower your data journey and the Power BI Community at large.
🔗 Curious to explore more? [Discover here].
Let’s keep building smarter solutions together!

MFelix
Super User
Super User

Hi @Read39487 ,

 

Try the following code:

Dynamic Text =	SWITCH(
		TRUE(),
		COUNTROWS('Table') = COUNTROWS(FILTER(
			ALL('Table'),
			'Table'[Group] = MAX('Table'[Group])
		)), SELECTEDVALUE('Table'[Group]),
		COUNTROWS(SUMMARIZE(
			'Table',
			'Table'[Group]
		)) = 1 &&
		COUNTROWS('Table') <= COUNTROWS(FILTER(
			ALL('Table'),
			'Table'[Group] = MAX('Table'[Group])
		)), CONCATENATEX(
			'Table',
			'Table'[Product],
			"/"
		),
		COUNTROWS('Table') = 1, SELECTEDVALUE('Table'[Product]),
		"Multiple Values"
	)

MFelix_0-1764762272362.png

MFelix_1-1764762281668.png

MFelix_2-1764762287496.png

MFelix_3-1764762293566.png

 

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





MattiaFratello
Super User
Super User

See the attached pbix

 

If this helped please feel free to mark it as a solution and give kudos 👍

rohit1991
Super User
Super User

Hii @Read39487 

 

To return dynamic text based on the selected products, you first need to detect how many items from Group 1 are selected. Once you know the count, you can build the text accordingly. A simple pattern is:

SelectedText :=
VAR L = VALUES('Table'[Product])
VAR C = COUNTROWS(L)
RETURN
SWITCH(
    TRUE(),
    C = 3, "Group 1",
    C = 1, MAX('Table'[Product]),
    C = 2, CONCATENATEX(L, [Product], "/"),
    "Multiple"
)

This returns “Group 1” when A,B,C are all selected, returns A, B, or C when only one is selected, and returns A/B, A/C, etc. when two are selected. This approach reliably handles all three scenarios you described.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors