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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
soarryan
Frequent Visitor

Creating a dynamic text field in DAX

I'm wondering if it is possible to create a dynamic text field in DAX that changes value based on a SWITCH statement. I know this is possible to do with calculated columns, but this will not be dynamic since calculated columns are computed at load time. I would like the user to be able to select a value in a slicer and the text field would dynamically change its value to the respective column in the dataset (e.g. select "Country" and the field would be [Country], select "Continent" and the field would be [Continent]).

5 REPLIES 5
PaulDBrown
Community Champion
Community Champion

If I'm understanding your request correctly, you need:

Selected region = IF(ISFILTERED(Disconnected Table [Field]), SELECTEDVALUE(Disconnected Table [Field]), "All Areas"),

 

or if you prefer to show nothing change "All Areas" to BLANK()





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thanks. Let me be more clear. I have two tables, one is the disconnected table, Table A, with one column containing the four values "Project", "Continent", "Sub Region", and "Country". The other table, Table B, is as shown below.

 

soarryan_0-1649951960586.png

 

I want to have a field in Table B that changes dynamically based on the selected value from Table A. For example if "Project" is selected in Table A, then the field in Table B would contain the values from the [Project] column.

Hi @soarryan 

 

To be dynamic, it should be a measure. The problem is that a measure should be aggregated and is expected to return only one value, so it is possible to return e.g. First or Last value in a field, or Count of a field. It cannot display multiple values at the same time. 

 

Here is one example

Measure = SWITCH(SELECTEDVALUE('Table A'[Type]),"Project",MAX('Table B'[Project]),"Country",MAX('Table B'[Country]),"Continent",MAX('Table B'[Continent]),"Sub Region",MAX('Table B'[Sub Region]))

vjingzhang_0-1650593962818.png

Another example

Measure 2 = SWITCH(SELECTEDVALUE('Table A'[Type]),"Project",COUNT('Table B'[Project]),"Country",COUNT('Table B'[Country]),"Continent",COUNT('Table B'[Continent]),"Sub Region",COUNT('Table B'[Sub Region]))

vjingzhang_1-1650594137488.png

 

You can see that I use Max and Count to aggregate every field in the measure. You can try using Values() to get the values in a field but when you put it into a visual, it will display an error saying "A table of multiple values was supplied where a single value was expected." If you want to display all values, you can use CONCATENATEX to concatenate the values in a column. What do you hope to do after getting the values in a column? 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

amitchandak
Super User
Super User

@soarryan , You can enable Q&A . and post that you can add the measures to your text box, you will get a + value option

 

You can have measure like selectedvalue(Table[Country]) , Sum(Table[Sales])  etc and use that

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thanks for the reply.

 

I'm not looking to change a field in a text box, rather a text column in the dataset. 

 

For example, the table below. I've created a disconnected table with only the text values "Project", "Continent", "Sub Region", and "Country". I have a slicer on the dashboard that allows the user to select one of these 4 text values. What I'm trying to do is have a text field that changes based on what the user selects in the slicer using a SWITCH statement. E.g. SWITCH(SELECTEDVALUE([Disconnected Table Field]), "Project", [Project], "Continent", [Continent], ...)

 

soarryan_0-1649950892230.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.