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
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

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
v-tangjie-msft
Community Support
Community Support

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

 

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 🙂 

v-tangjie-msft
Community Support
Community Support

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
Post Prodigy
Post Prodigy

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
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.