Naming issue for SWITCH True logic

Good Morning,

I have a Power BI Report that is using the small multiples to display the Top 30 Customers.

The Line chart will show me Total Sales, Total Profit or Total Quantity depending on the following DAX formula:

Metric Selected = SELECTEDVALUE( ‘Metric Selection’[Metric] ) - these values are coming from a table I created for Sales, Profit, Quantity and reference in the following DAX formula:

Value Selected =
SWITCH( TRUE(),
‘Metric Selection’[Metric Selected] = “Sales”, [Total Sales],
‘Metric Selection’[Metric Selected] = “Profit”, [Total Profit],
‘Metric Selection’[Metric Selected] = “Quantity”, [Total Quantity],
[Total Sales])

Everything displays correctly in the Line Chart when I use a Slicer to see either Sales, Profit or Quantity.

My question is, is there a way to get the value in the Line Chart to Show Either Sales, Profit or Quantity in the Tooltip that pops up when I hover over it. Right now, it shows the name of the Measure “Value Selected” as it should - but is it possible to have that name be something else that can vary (Sales, Profit, Quantity)…

Thanx,

Guy

@GuyJohnson

Could you provide a test .pbix file? That will likely get more responses as forum members won’t be required to mock one up themselves when testing solutions for you.

@HufferD

Thanx for the response but I cannot provide the .pbix file as the data is very sensitive.

This question was mostly just an inquiry to see if there is an obvious solution which I’m thinking there isn’t.

Guy

@GuyJohnson

Understood on the sensitive data.

You could create a new measure similar to the one you have that returns the name of the currently selected metric:

Dynamic Tooltip Text = 
SWITCH(
  TRUE(),
  ‘Metric Selection’[Metric Selected] = "Sales", "Total Sales",
  ‘Metric Selection’[Metric Selected] = "Profit", "Total Profit",
  ‘Metric Selection’[Metric Selected] = "Quantity", "Total Quantity",
  "No Metric Selected"
)

Then, in your tooltip settings, you could use this ‘Dynamic Tooltip Text’ measure to display the metric name dynamically.

@HufferD

Thanx for the Measure but it doesn’t solve the issue. This measure effectively does the same as my measure in what it will display:

Dynamic Tooltip Text Total Sales => both of these entries being simple text

What I’m looking for is, when I select from my Slicer either Sales, Profit or Quantity referencing my Metric Selected table, to see not the name of the measure but the following:

Total Sales $1,000,000 => and the same for the other 2 selections.

I’m beginning to believe that this is not possible as the underlying DAX code will only select the name of the Measure.

It’s not a big deal in the long run, I was just thinking that to display the actual name and value would look better. My work around will be the rename the Measure to Value and go with it.

Guy

@GuyJohnson

That clarifies things a bit. You’re looking to display both the metric name and the corresponding value in a tooltip.

I don’t have anything to test this on, but you could potentially do this using a concatenated string in a new measure:

Dynamic Tooltip Info =
CONCATENATE(
    SWITCH(
        TRUE(),
        ‘Metric Selection’[Metric Selected] = "Sales", "Total Sales: $",
        ‘Metric Selection’[Metric Selected] = "Profit", "Total Profit: $",
        ‘Metric Selection’[Metric Selected] = "Quantity", "Total Quantity: ",
        "No Metric: "
    ),
    FORMAT(
        SWITCH(
            TRUE(),
            ‘Metric Selection’[Metric Selected] = "Sales", [Total Sales],
            ‘Metric Selection’[Metric Selected] = "Profit", [Total Profit],
            ‘Metric Selection’[Metric Selected] = "Quantity", [Total Quantity],
            BLANK()
        ),
        "#,##0"
    )
)

Try this Dynamic Tooltip Info.

@HufferD

Thanx for this. It did help a bit but and I guess it’s the elephant in the room.

When I use the Measure, you gave me I do get Total Sales: $1,000,000 and the same for Profit & Quantity.so that part is working.

The issue is the tooltip still attached the Measure’s name to it as follows:

Measure Name Total Sales: $1,000,000

I think we are tilting at the windmill to get any but the actual Measure name.

I appreciate your work on this, but I think in the end it’s fruitless.

I’m going to borrow your Measure and rename it Value, so it reads somewhat logically.

Guy

@GuyJohnson,

What you’re seeing with that is just a problem with the filter context in your measure. It’s an easy fix.

@HufferD

I took a page from Sam and asked ChatGPT for some help with this.

This is what it recommended:

In Power BI, you cannot directly change the measure’s name dynamically based on the selected slicer value because measure names are static within your data model. Measures are typically given static names when defined in DAX.

However, you can create a workaround to achieve a similar effect by adding a card visual or a text box to your report page. In this card or text box, you can display the selected metric name from your slicer, and next to it, you can display the dynamic value using the “Dynamic Tooltip” measure we created earlier. Here’s how you can do it:

  1. Add a card visual or a text box to your report page.
  2. In the Values field well of the card visual or text box, add the measure that captures the selected metric from your slicer. Let’s call this measure “Selected Metric.”
  3. Create a DAX measure to capture the dynamic tooltip value as previously shown:

DAXCopy code

Dynamic Tooltip = 
VAR SelectedMetric = SELECTEDVALUE('Metric Selection'[Metric])
RETURN
    SWITCH(
        SelectedMetric,
        "Sales", "Total Sales: " & FORMAT([Total Sales], "Currency"),
        "Profit", "Total Profit: " & FORMAT([Total Profit], "Currency"),
        "Quantity", "Total Quantity: " & FORMAT([Total Quantity], "#,##0")
    )
  1. Next to the card visual or text box displaying the selected metric, add another text box that references the “Dynamic Tooltip” measure:

mathematicaCopy code

[Dynamic Tooltip]
  1. Now, when you change the metric selection in your slicer, the card visual or text box will update to display the selected metric, and the adjacent text box will display the dynamic tooltip value accordingly.

This approach allows you to provide a dynamic tooltip-like experience, where the metric name in the card or text box changes based on the slicer selection, and the adjacent text box displays the corresponding dynamic value. While it’s not the measure name itself that changes, it achieves a similar result in your report.

The Measure is almost identical to yours - so thanx for that.

What I have now is a popup card that shows what I need.

Guy

1 Like