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
Anonymous
Not applicable

Dax query for making slicer with column name

Hi Everyone,

I wanted to create a slicer based on column name
I have created a visual based on two column 2021 and 2022 data, but I want a slicer name "2021" and "2022"
And when I click on 2021, it show visual values of 2021 Light Blue one and same for 2022 Dark Blue one
And If I don't click on anyone of slicer it shows the following

Thank you

dawoodrana99_1-1661886244442.png

 



dawoodrana99_0-1661886189887.png

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@Anonymous 

There are two methods. 


First one which I recommend is to edit the code of the table in a way that makes it unpivoted.

 

The 2nd solution is to create a new unpivoted calculated table using dax (refer to following code). However, this code shall provide an idea on how to edit the code of the original table

NewTable =
UNION (
    SELECTCOLUMNS (
        OldTable,
        "Category", OldTable[Category],
        "Year", 2021,
        "Total", OldTable[Total 2021]
    ),
    SELECTCOLUMNS (
        OldTable,
        "Category", OldTable[Category],
        "Year", 2022,
        "Total", OldTable[Total 2022]
    )
)

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

@Anonymous 

There are two methods. 


First one which I recommend is to edit the code of the table in a way that makes it unpivoted.

 

The 2nd solution is to create a new unpivoted calculated table using dax (refer to following code). However, this code shall provide an idea on how to edit the code of the original table

NewTable =
UNION (
    SELECTCOLUMNS (
        OldTable,
        "Category", OldTable[Category],
        "Year", 2021,
        "Total", OldTable[Total 2021]
    ),
    SELECTCOLUMNS (
        OldTable,
        "Category", OldTable[Category],
        "Year", 2022,
        "Total", OldTable[Total 2022]
    )
)
tamerj1
Super User
Super User

Hi @Anonymous 

you need first to unpivot the two columns using power query. The column names will become values of the Attributes column then you can use it for slicing 

Anonymous
Not applicable

Hi @tamerj1 ,

I have created this table based on other tables values, I can't take this table to Edit Query mode
If there is a way, then kindly guide me

Thank you

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.