Mukul Kumar
Mukul Kumar

Reputation: 724

PowerBI Line Chart - Show percentage on hover

In the line chart, when hovering, it shows the count for each legend (see Pic 1 for reference). What I want is to display the percentage at the day level in brackets alongside the count on hover.

enter image description here

I tried using a tooltip, but it created an extra line, which feels redundant and doesn't look good (see Pic 2 for reference). Additionally, with the tooltip, I am unable to get the percentage at the day level. The percentage is using the total count for all days in the denominator, which I don't want.

enter image description here

I think the DAX query for the tooltip measure is correct, but I'm still not getting the percentage at the day level.

Transaction Count with Status Percentage = 
VAR CurrentStatusTransactions = SUM('Table'[transactions])
VAR TotalStatusTransactions = 
    CALCULATE(
        SUM('Table'[transactions]),
        ALLEXCEPT('Table', 'Table'[UploadTime], 'TableStatus'[Status])
    )
VAR Percentage = DIVIDE(CurrentStatusTransactions, TotalStatusTransactions, 0) * 100
RETURN 
     FORMAT(Percentage, "0.00") & "%"

Help 1 - Can you suggest how to achieve displaying the percentage alongside the count in brackets on hover?

Help 2 - If the first option isn't possible, please help me fix my tooltip measure DAX query.

Here’s more context on the data:

The DAX query I wrote is intended for the tooltip to show the percentage of each individual status per day. However, it’s not providing the desired percentage at the day level.

Upvotes: 0

Views: 48

Answers (1)

Sam Nseir
Sam Nseir

Reputation: 12111

You will need to get Help 2 working first - ie your Measure.

Use ALLSELECTED like so:

// measure 1
# Transactions = SUM('Table'[transactions])

// measure 2
Status Mix % = 
  DIVIDE(
    [# Transactions],
    CALCULATE([# Transactions], ALLSELECTED('TableStatus'[Status])),
    0
  )

Note: Don't multiply by 100 and don't use FORMAT as otherwise your measure will be a string. Instead, set the Format to Percentage for the measure in the Measure tools tab.


Now for Help 1, displaying a second value in the tooltip within brackets.
We can achieve this with Dynamic Format strings.

Create a new Measure:

# Transactions w/ StatusMix = [# Transactions]

In the Measure tools tab, set its Format to Dynamic and use the following for Format:

"#,0" & " (""" & FORMAT([Status Mix %], "0.00%") & """)"

The one downside to this is that it will apply the same format to your Y-axis Values, which you can switch off in the Properties of the visual.

Example

Upvotes: 0

Related Questions