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
webportal
Impactful Individual
Impactful Individual

Dynamic names for the fields in the "Values" area of a matrix

Is there any way of defining dynamic names for the fields in the "Values" area of a matrix?

 

I know we can double click on them and manually change the name, but can we make it dependent on a slicer value, for example?

 

Thanks in advance!

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @webportal ,

Sorry for late reply ,you could use the following formula:

flagForSelected =
VAR _sele =
    SELECTEDVALUE ( YearSlicer[year] )
RETURN
    IF (
        _sele = SELECTEDVALUE ( Dynamic2[Year] )
            || _sele
                = SELECTEDVALUE ( Dynamic2[Year] ) + 1,
        1
    )
toRemoveOtherColumns =
SUM ( Dynamic2[Count] ) * [flagForSelected]
sumForRow =
SUMX ( Dynamic2, [toRemoveOtherColumns] )

The matrix looks like this:

8.18.fo.PNG

Did I answer your question ? Please mark my reply as solution. Thank you very much.

If not, please upload some insensitive data samples and expected output.

 

Best Regards,

Eyelyn Qin

 

View solution in original post

8 REPLIES 8
v-eqin-msft
Community Support
Community Support

Hi @webportal ,

Sorry for late reply ,you could use the following formula:

flagForSelected =
VAR _sele =
    SELECTEDVALUE ( YearSlicer[year] )
RETURN
    IF (
        _sele = SELECTEDVALUE ( Dynamic2[Year] )
            || _sele
                = SELECTEDVALUE ( Dynamic2[Year] ) + 1,
        1
    )
toRemoveOtherColumns =
SUM ( Dynamic2[Count] ) * [flagForSelected]
sumForRow =
SUMX ( Dynamic2, [toRemoveOtherColumns] )

The matrix looks like this:

8.18.fo.PNG

Did I answer your question ? Please mark my reply as solution. Thank you very much.

If not, please upload some insensitive data samples and expected output.

 

Best Regards,

Eyelyn Qin

 

v-eqin-msft
Community Support
Community Support

Hi @webportal ,

According to your description, you want to dynamically display values in matrix based on slicer, right?

My data sample looks like this:

8.18.6.PNG

After doing “Pivot” for “Date” column(value column is “Count”) in Query Editor ,you could use the following formula:

lastYear =
VAR a =
    SUM ( 'Dynamic'[2017] )
VAR b =
    SUM ( 'Dynamic'[2018] )
VAR c =
    SUM ( 'Dynamic'[2019] )
VAR selector =
    MAX ( ForSlicer[Year] )
RETURN
SWITCH ( selector, 2017, BLANK (), 2018, a, 2019, b, 2020, c )
thisYear =
VAR a =
    SUM ( 'Dynamic'[2017] )
VAR b =
    SUM ( 'Dynamic'[2018] )
VAR c =
    SUM ( 'Dynamic'[2019] )
VAR d =
    SUM ( 'Dynamic'[2020] )
VAR selector =
    MAX ( ForSlicer[Year] )
RETURN
SWITCH ( selector, 2017, a, 2018, b, 2019, c, 2020, d )

My matrix visual looks like this:

8.18.7.png

Is the result what you want? If not, please upload some data samples and expected output.

Please do mask sensitive data before uploading.

 

Best Regards,

Eyelyn Qin

Hello @v-eqin-msft 

 

Thanks for helping.

To achieve that solution, it would be enough to simply double click the measures names and replace them by "this year" and "last year".

 

What I need is this:

 

Anotação 2020-08-18 095005.jpg

edhans
Super User
Super User

Hi @webportal I am not aware of a way to change the column names based on a slicer selection. You can change the names in Power Query, before the import, but once in the Power BI DAX side, that name is fixed.

You can change the measure used based on a slicer selection, and use conditional formatting to change what is shown in the report. See this article on how to change the measure used. It uses SWITCH() to work.

 

There are some components of a visual that can be based on a measure, like the visual title. You can use conditional logic to change what the visual title is for example:

edhans_0-1597687597177.png

But I know of no way to change the actual field name.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
webportal
Impactful Individual
Impactful Individual

Hi @edhans and@amitchandak 

 

Thanks for helping, maybe I haven't explained myself properly.

 

I want to change the names of two measures in the "Values" field:

 

[SalesThisYear]

[SalesLastYear]

 

If the user selected 2020 in the slicer, this would mean the names of what I see in the matrix would be:

2020

2019

@webportal Just put the year field from your date table in your visual as an axis, column header, etc. The slicer will filter it to show the proper year as that is the same field.

 

Your data is sales (or whatever.) Sales is sales. Sales isn't 2019 or 2020. The years are dimensions that describe sales, and those will change based on a slicer selection. But sales is just sales. It will recalculate to only show the total for 2019, or 2020, or both if you have multi-select enabled for the slicer.

 

Make sense?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
webportal
Impactful Individual
Impactful Individual

@edhans, thanks for your help.
However, I have more than these two columns on the matrix. For example, I have a 3rd column with the variation from one year to another, so placing the year on the columns wouldn't work.
amitchandak
Super User
Super User

@webportal , refer if this can help

dynamic Column Header
https://www.youtube.com/watch?v=yEemVBiaTuk
https://www.goodly.co.in/dynamic-column-names-power-query/
https://www.thebiccountant.com/2018/07/04/efficiently-rename-column-names-with-a-function-in-power-b...
https://community.powerbi.com/t5/Desktop/Dynamic-column-name-from-its-value/td-p/189442

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register 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!

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.