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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
vgk_17
Frequent Visitor

Dynamically Create Column Using Slicer

Hi,

 

I have 2 tables - X (contains Name and Address columns) and Y (Contains Attribute column) as follows. I am feeding Attribute as slicer. I need to dynamically create in X table based on slicer selection.

NameAddress
A1
B2
C3

 

Attribute
Name_Attribute
Address_Attribute

 

When I select Name_Arttribute in slicer, then I should get table X with additional column New_Col which should have its values copied from Name column of the table X. And When I select Address_Arttribute in slicer, then I should get table X with additional column New_Col which should have its values copied from Address column of the table X

 

When Slicer selection - Name_Attribute, then table X

NameAddressNew_Col
A1A
B2B
C3C

 

When Slicer selection - Address_Attribute, then table X

 

NameAddressNew_Col
A11
B22
C33

 

I am using following DAX, but it is not working - 

 

New_Column = Switch(

selectedvalue(Attribute)),

"Name_Attribute", [Name],

"Address_Attribute",[Address]

)

 

And when I used following DAX, no matter what slicer selection is made, it is always picking up Address_Attribute and giving 1,2,3 in New_Col

 

Column = Switch(

FirstNonBlank(Attribute),1),

"Name_Attribute", [Name],

"Address_Attribute",[Address]

)

 

Any help here is highly appreciated.

 

Thanks

5 REPLIES 5
vgk_17
Frequent Visitor

I would like to clarify one point here - New_Col is a column, not the measure. Hence, I am right clicking on table X and then clicking on New Column instead of New Measure. Reason is, I need to further use this column in Matrix where only columns can be supplied, not the measures.

 

Looping in users that I see respond often on community.

 

@CheenuSing @amitchandak @Greg_Deckler @parry2k 

@vgk_17 - You cannot create a column that responds to user input on a slicer. The reason is that calculated columns are only calculated at the time of data refresh.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

Thanks for looking into it and replying. My objective here is to create a heat map using my repurposing matrix. I want Rows and Columns in that matric to be dynamic. This essentially means if we have say 10 columns in my table, I want to give user 2 slicers which user can use to select Rows and Columns of this matrix dynamically. Since I am talking about matrix, it only accepts Columns in Rows/Columns field. Hence cannot user measure. Any solution on how can I achieve this ?

 

Also, regarding calculated column being initialized at the time of data refresh, here is what I did to achieve this calculated column to respond on slicer selection -

1. Inserted index column in main data and created this table's duplicate

2. In the duplicate table, barring index column and the columns I want to toggle between, removed rest all. Then seleted all columns barring index and unpivoted it.

3. Made Many to 1, both relation between Main data table and duplicate data table.

4. Created another table with just 1 column and entered A and B in its column as values. This is my slicer table.

5. Created many to one, single relation between duplicate table and slicer table

6. In the duplicate table, created a calclated column with following dax-

Calculated_Column =
SWITCH(
FIRSTNONBLANK('SlicerTable'[SlicerTableColumn],TRUE()),
"A", RELATED(Main_Data[Main_Data_Col_1]),
"B", RELATED(Main_Data[Main_Data_Col_2])
)
7. Dragged Calculated_Column on canvas as a table.
8. Now when I change any value in slicer, this calculated column takes approproate value. On selecting A, it takes value from Main_Data_Col_1 and on selecting B, it takes value from Main_Data_Col_2.
 
I want to achieve the same in main table and not in the duplicate table, anything that you can come up / suggest ?
 

@vgk_17 - Just so you understand that you cannot create a calculated column based upon a slicer selection. That's what it sounded like what you were doing. If you want to achieve some kind of dynamic display of information based upon a slicer selection, that is a different matter. I would suggest review the following link because I am still not exactly clear what you are trying to achieve. Pictures often help.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Dynamic-EVERYTHING-measures-axis-legend-titl...

 


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

Unfortunately i cannot provide pictures. I will try to be more clearer.

My end goal is to create Heat Map. Since this visualization is not available in PowerBI, I will use Matrix visualization and apply color gradient on its values to make it look like heat map.

I have 3 tables as listed below (no relationship exists between these 3)

NameAddressEmp IDMarks
AA1A12310
BA2B12320
CA3C12330

 

Row Slicer
Name
Address

Emp ID

 

Column Slicer
Name
Address
Emp ID

 

When user will select Name in row slicer and Address in column slicer, then I should get below matrix-

 A1A2A3
A   
B   
C   

 

When user will select Name in row slicer and Emp ID in column slicer, then I should get below matrix-

 A123B123C123
A   
B   
C   

 

When user will select Address in row slicer and Name in column slicer, then I should get below matrix-

 ABC
A1   
A2   
A3   

 

So basically, I am giving user the flexibility to be able to select which two columns he/she would like to add to the Matrix. I hope now It is clear. Any solution/idea that you could suggest. Thank you.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.