Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Change column field in matrix/table using slicer

Hi, I have a table visual which shows Sales by Region i.e. North, East. 

Sales by Region

What I want to achieve is, that when I select any region from slicer (I have a dropdown slicer of region), the same table show sales data by State of that selected region. (States in place of region in the same table).

I have tried few ways, like tried to create a measure, which can switch column dynamically (switch case, when region = 'east', then state column). Read this article : https://www.nathanprats.com/4-different-ways-to-dynamically-change-tables-rows-in-power-bi/ but this use case seems different. There are many tutorials which show how to dynamically add column which is not the use case here.

 

What I tried, is that I first checked if any region is selected, if yes then checked if any state is selected:

switch to this in table
= IF(ISBLANK([sel_region]),"R",IF(ISBLANK([sel_state]),"S","C")).
So in this way I am able to return, and find out what is selected.
 
 And, then on the basis of this value when I tried to switch column, this is where I get stuck.
Measure 7 = SWITCH(
    true(),
    [switch to this in table]="R",VALUES(Orders[Region]),
    [switch to this in table]="S",VALUES(Orders[State/Province]),
    [switch to this in table]="C",VALUES(Orders[City])
)
 
Is there a way through which I can simply call/use column from my table directly without the use of values or anything else. Simply, replacing switching column name. See below that how and where I am thinking to change column dynamically
If any region is selected, then instead of "Region", here I am trying to pull "State" column. Once the state column will be placed here, it will automatically obey the filter context of region slicer and will show only states from that region.

 

Any help is much appreciated!

2 Replies