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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Judy101
Frequent Visitor

DAX: Slicer to change text values in a column for certain rows & have ability to filter the column

Hi,

Looking for a measure to resolve this. 

 

I have a table with multiple columns. 2 of those are Team, and Team_Category.

There are some teams that happen to fall in 2 categories: Category X, Category Y.

 

If I put Team Category in slicer, when user selects Category X, those specific teams in the table should represent Category X under Team Category Column, and if Category Y is selected, those specific in the table should represent Category Y under Team Category Column.

 

If nothing is selected for the slicer, the default values for those teams should be "Category X & Category Y".

I want to create a slicer that can not only does the above but also have ability to filter the table based on slicer selection. 

 

I assume it maybe a combination of selectedvalue, switch, and userelationship/crossfilter but I can't really arrive at a cohesive solution.

 

This is the DAX i could get to but this prevents the slicer from being able to filter table based on slicer selection. This is the measure being fed to the table instead of the original Team Category column, and a dummy column is created which is acting as slicer with values : Category A, Category B, Category X, Category Y.

 

Value Type =

VAR selected_value =

SELECTEDVALUE('Type Slicers'[Column1],"Category A")

 

RETURN

SWITCH(

        selected_value,

    "Category A",MAX(Teams[Team_Category]),

    "Category X",MAX(Teams[Team_Category_CATXModified]),

    "Category Y",MAX(Teams[Team_Category_CATYModified]),

    "Category B",MAX(Teams[Team_Category]),

  BLANK()

    )

 

Below are the calculated columns along with original column.

Judy101_1-1701073476322.png

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Judy101 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a measure. 

Flag = IF(OR([Value Type] in VALUES('Slicer Table'[Column1]),ISFILTERED('Slicer Table'[Column1])=FALSE()),1,0)

(3) Then the result is as follows.

vtangjiemsft_0-1701135962012.png

 

Best Regards,

Neeko Tang

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

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @Judy101 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2)Click "transform data" to enter the power query, copy the source table to delete the rest of the columns and keep only the [Category] column and then split according to "&" and then transpose. Open "Advanced Editor", copy and paste the following code. You can check the steps in the right hand side step bar.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4sSU3PL6pUcFTSUTJUitVBEnICChmhCkUoxJQaGBiZKcBFIoGKjJViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Value", type number}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Value"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns", "Category", Splitter.SplitTextByDelimiter("&", QuoteStyle.Csv), {"Category.1", "Category.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Category.1", type text}, {"Category.2", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {}, "Attribute", "Value"),
    #"Removed Columns1" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Replaced Value" = Table.ReplaceValue(#"Removed Columns1"," ","",Replacer.ReplaceText,{"Value"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","Category","Category ",Replacer.ReplaceText,{"Value"}),
    #"Renamed Columns" = Table.RenameColumns(#"Replaced Value1",{{"Value", "Slicer Team_Category"}})
in
    #"Renamed Columns"

(3) We can create calculated columns.

Team_Category_CATXModified = TRIM( LEFT([Team_Category],IF(FIND ( "&", [Team_Category],1,BLANK())-1<=0,0,FIND ( "&", [Team_Category],1,BLANK())-1)))
Team_Category_CATYModified = TRIM(RIGHT([Team_Category],IF(FIND ( "&", [Team_Category],1,BLANK())-1<=0,0,FIND ( "&", [Team_Category],1,BLANK())-1)))

(4)We can create a measure.

Flag = 
SWITCH(TRUE(),
ISFILTERED('Table (2)'[Slicer Team_Category])=FALSE(),1,
SELECTEDVALUE('Table (2)'[Slicer Team_Category])=MAX('Teams'[Team_Category]),1,
SELECTEDVALUE('Table (2)'[Slicer Team_Category])=MAX('Teams'[Team_Category_CATXModified]),1,
SELECTEDVALUE('Table (2)'[Slicer Team_Category])=MAX('Teams'[Team_Category_CATYModified]),1,0)

(5) Then the result is as follows.

vtangjiemsft_0-1701078758441.png

 

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

I am somehow unable to add the pbix. Adding snaps for your ref.

 

State in which nothing is selected from the dummy slicer:

 

Judy101_0-1701083059739.png

What happens if I selected Category X , Category Y - Team E & F will appear under Category X, and Category Y accordinly.

 

Judy101_1-1701083121889.pngJudy101_2-1701083136909.png

This part is great, but I want it to have the ability to work like a slicer. Only rows that correspond to that category should remain in the table. That is where I am struggling.

 

To achieve the above, I created a Slicer Table within Powerbi which has a Column containing categories:

Judy101_3-1701083244335.png

and has a measure called Value Type (that you see in the above Table visual screenshots) - 

 

Value Type =
VAR selected_value =
SELECTEDVALUE('Slicer Table'[Column1], "Category A")

RETURN
SWITCH(
        selected_value,
    "Category A",MAX('Dummy Data'[Team Category]),
    "Category B",MAX('Dummy Data'[Team Category]),
    "Category C",MAX('Dummy Data'[Team Category]),
    "Category D",MAX('Dummy Data'[Team Category]),
    "Category X",MAX('Dummy Data'[Team_Category_CATXModified]),
    "Category Y",MAX('Dummy Data'[Team_Category_CATYModified]),
  BLANK()
    )
 
The calculated columns are :
Team_Category_CATXModified =
IF(
    'Dummy Data'[Team Category] = "Category X & Y", "Category X", 'Dummy Data'[Team Category]
)
 
Team_Category_CATYModified =
IF(
    'Dummy Data'[Team Category] = "Category X & Y", "Category Y", 'Dummy Data'[Team Category]
)
 
 
The slicer is based on Column 1 from Slicer Table. 
 
The DAX above needs to also use a virtual relationship which I am unable to establish. 
 
Judy101_4-1701083876844.png

 

Anonymous
Not applicable

Hi @Judy101 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a measure. 

Flag = IF(OR([Value Type] in VALUES('Slicer Table'[Column1]),ISFILTERED('Slicer Table'[Column1])=FALSE()),1,0)

(3) Then the result is as follows.

vtangjiemsft_0-1701135962012.png

 

Best Regards,

Neeko Tang

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

This was super helpful thank you 🙂 

 

I may have more questions wrt this slicer interacting with other visuals & slicers on the dashboard. I will get back on this chain 🙂 

Anonymous
Not applicable

Hi @Judy101 ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or if you are still confused about it, please feel free to let me know.

 

Best Regards,

Neeko Tang

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

Hi Neeko,

 

I have rephrased my query. Hopefully the question makes more sense now. 

Unfortunately, I am looking for DAX solution for this. So I cannot say it's resolved at this stage.

Rupak_bi
Solution Sage
Solution Sage

Go to Query editor ---->Split the category column Based on "&" ----> Unpivot all the splitted column and then save it.

now use your value column as slicer and in matrix to get desired result.



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

Hi Rupak,

 

I changed my query to make more sense. I do not think the original ask was clear.

I am looking for DAX to help here 🙂 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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