Forum Discussion
SELECTEDVALUE Format Strings not working for Chart Axis
- 10 months ago
Hi ajohns3 ,
Thank you for reaching out to the Microsoft Community Forum.
This is a known limitation in Power BI, dynamic format strings when used with SELECTEDVALUE() and when the measure is plotted on chart axes like Y-axis, X-axis, or secondary axis.
Please try below alternative workarounds.1. Use a calculation group for formatting, Create a format calculation item that handles display logic separately.
SELECTEDVALUE('Fruit Table'[Fruit Name], "Multiple Fruit Types")
And assign that as a dynamic string expression in a calculation group.
2. You can use an intermediary variable.Fruits Available =
VAR _value = SUM('Table'[Number of Fruits])
VAR _fruit = SELECTEDVALUE('Table'[Fruit Name])
RETURN
_valueFormat string:
VAR _fruit = SELECTEDVALUE('Table'[Fruit Name])
RETURN
"#,0 " & IF(NOT(ISBLANK(_fruit)), _fruit, "Multiple Fruit Types")Note: This doesn’t fix the axis issue in all visuals, but helps make behavior consistent in tables/cards.
3. If you are expecting user communication not formatting logic, consider leaving the measure format as static , and use a dynamic text label like card/visual title instead.
Title_Fruits =
"Fruits Available - " &
SELECTEDVALUE('Table'[Fruit Name], "Multiple Fruit Types")Then show that in the chart title or subtitle dynamically. This keeps the axis numeric.
I hope this information helps. Please do let us know if you have any further queries.
Regards,
Dinesh
- 10 months ago
Thanks v-dineshya,
I tried out your second solution. The calculation item solution I would like to avoid as I do make use of implicit measures.
The format string you suggest
VAR _fruit = SELECTEDVALUE('Table'[Fruit Name]) RETURN "#,0 " & IF(NOT(ISBLANK(_fruit)), _fruit, "Multiple Fruit Types")does seem to produce the desired result.
I have also found that adding an ALLSELECTED() filter to the format string also gives the desired result.
"#,0 " & CALCULATE(SELECTEDVALUE('Table'[Fruit Name], "Multiple Fruit Types"), ALLSELECTED())I expect there are situations where these approaches will diverge.
Hi ajohns3 ,
Thank you for reaching out to the Microsoft Community Forum.
This is a known limitation in Power BI, dynamic format strings when used with SELECTEDVALUE() and when the measure is plotted on chart axes like Y-axis, X-axis, or secondary axis.
Please try below alternative workarounds.
1. Use a calculation group for formatting, Create a format calculation item that handles display logic separately.
SELECTEDVALUE('Fruit Table'[Fruit Name], "Multiple Fruit Types")
And assign that as a dynamic string expression in a calculation group.
2. You can use an intermediary variable.
Fruits Available =
VAR _value = SUM('Table'[Number of Fruits])
VAR _fruit = SELECTEDVALUE('Table'[Fruit Name])
RETURN
_value
Format string:
VAR _fruit = SELECTEDVALUE('Table'[Fruit Name])
RETURN
"#,0 " & IF(NOT(ISBLANK(_fruit)), _fruit, "Multiple Fruit Types")
Note: This doesn’t fix the axis issue in all visuals, but helps make behavior consistent in tables/cards.
3. If you are expecting user communication not formatting logic, consider leaving the measure format as static , and use a dynamic text label like card/visual title instead.
Title_Fruits =
"Fruits Available - " &
SELECTEDVALUE('Table'[Fruit Name], "Multiple Fruit Types")
Then show that in the chart title or subtitle dynamically. This keeps the axis numeric.
I hope this information helps. Please do let us know if you have any further queries.
Regards,
Dinesh
- ajohns310 months agoAdvocate I
Thanks v-dineshya,
I tried out your second solution. The calculation item solution I would like to avoid as I do make use of implicit measures.
The format string you suggest
VAR _fruit = SELECTEDVALUE('Table'[Fruit Name]) RETURN "#,0 " & IF(NOT(ISBLANK(_fruit)), _fruit, "Multiple Fruit Types")does seem to produce the desired result.
I have also found that adding an ALLSELECTED() filter to the format string also gives the desired result.
"#,0 " & CALCULATE(SELECTEDVALUE('Table'[Fruit Name], "Multiple Fruit Types"), ALLSELECTED())I expect there are situations where these approaches will diverge.