powerbivisualizationfield# power bi dynamically change measure values and names with filters

I have a slicer with two values A and B(single select).

I also have two measures that countrows based on some condition, [M1] and [M2]. I need to use these measures in some visuals( a matrix/ stacked column chart etc). When filter A is applied, I need to show [M1] values only and when filter B is applied i need [M2] values only,

I was able to do this using a dax switch measure or field parameter But the field names are not as expected in the visuals

Using switch:
M1/M2= `SWITCH(SELECTEDVALUE( Table[Filtercolumn]),"A", [M1],"B", [M2], BLANK())`

In matrix visual I get the following result:

Id | M1/M2 |
---|---|

1 | 12 |

2 | 20 |

Even though the values(count) is populating correctly when filters are applied the heading remains as **M1/M2**, but I need **either M1 or M2 based on filter selected**

when using field parameters:

when filter A applied

Id | M1 | M2 |
---|---|---|

1 | 12 | |

2 | 20 |

when filter B applied

Id | M1 | M2 |
---|---|---|

1 | 34 | |

2 | 26 |

Here the heading and values are proper but **blank columns are not required.**

Sample screenshot:

Is there any work around to get below result when filter A applied:

Id | M1 |
---|---|

1 | 12 |

2 | 20 |

when filter B is applied:

Id | M2 |
---|---|

1 | 34 |

2 | 26 |

Solution

Update your `Table`

to have two columns like:

FilterColumn | LabelColumn |
---|---|

A | M1 |

A | G1 |

A | S1 |

A | B1 |

B | M2 |

B | G2 |

B | S2 |

B | B2 |

Now use the LabelColumn in the Matrix visual in Columns, and use your `M1/M2`

measure in Values of the Matrix. For other visuals, use the LabelColumn for Legends. That should be it.

Note: Not possible to do this with the plain Table visual. Columns will always be visible and you cannot dynamically name the columns, in the Table visual.

**Update**

If you aleady have four measure for Mx, Gx, Sx, Bx then add one more column like so:

FilterColumn | LabelColumn | Category |
---|---|---|

A | M1 | M |

A | G1 | G |

A | S1 | S |

A | B1 | B |

B | M2 | M |

B | G2 | G |

B | S2 | S |

B | B2 | B |

Then create a new measure that looks like this:

```
Meaningful Name = SWITCH( SELECTEDVALUE(Table[Category]),
"M", [M1/M2],
"G", [G1/G2],
"S", [S1/S2],
"B", [B2/B2]
)
```

- How to change the base function in Dax
- SWITCH Function with multiple hits - Power Query
- Select categories in dropdown-menu with selenium
- Power BI need to separate column values into rows but there is no delimeter
- Power Query Editor - Format Column
- PowerBI Matrix with Year and Month
- How to remove the filtered items from Rankx function in power bi
- Power BI star (constellation) schema: 2 fact tables with relation between each other
- Newest version of Deneb does not handle Scrolling when data overflows
- Check existing value on different table in PowerBi
- Get the complete data of a visual in powerbi from an embedded report and export to CSV/excel
- Slicer doesn't show column with zero value
- Zero value replace by average value by catagory
- Calculate a rate by category (DAX, PowerBI)
- Refresh power pivot-power query
- How to filter using hierarchical relationships within Power BI
- What's the difference between DAX and Power Query (or M)?
- Display previous attendance figure
- Trouble in SVG Sales Sum and Average Display
- PowerBI Service Assign Workplace for different people
- Power BI Subtract 1 from column where date matches
- group and sum in DAX
- Power BI conditional formatting - matrix and multiple conditions
- filter, multiply, and sum in dax
- FILTER and SUMX in DAX
- Weighted Average Cost in POWER QUERY
- Has anybody created a Joint Plot (Density in middle/Distributions across the axis) in Power BI without Python/R? How?
- How can I calculate the number of IDs for the previous month?
- How to join three tables without primary key?
- How to change number format in power editor?