Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PBI-Dash
Frequent Visitor

Dynamic x axis with different formatting in a bar chart

Hi,

 

I'm trying to have a bar chart with a dynamic x-axis based on a slicer selection. The users should be able to select % or # in a slicer and the result should either be shown in percentage or whole number. The issue that I'm facing is that I can't seem to be able to get the fomatting done correctly.

 

I've tried different expressions but they all seem to format the values as text. And it doesn't seem like I can have text as "Values" in a bar chart. It works fine in a table, but not in a bar chart.

 

[Package Conversion] and [Packages] seen below are two separate measures.

 

My expression is:

Packages Confirmed = 
IF(
    HASONEVALUE(MeasureSelection[Selection]),
    SWITCH(
        VALUES(MeasureSelection[Selection]),
        "%",
        FORMAT([Package Conversion],"Percent"),
        "#",
        FORMAT([Packages],"General number")
    )
)

 

PBIDash_0-1649661726242.png

 

I've also tried with this expression as I saw in another post, but I didn't get it to work either.

Packages Confirmed = 
SWITCH(
    VALUES(MeasureSelection[Selection]), 
    "%",
    FORMAT([Package Conversion],"0.00%;(0.00%);0"),
    "#",
    FORMAT([Packages],"0.00;(0.00);0")
)

 

Is this possible in Power BI? Or do I have to look into calculation groups in Tabular Editor?

 

Sincerely

Dash

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @PBI-Dash 

 

This can be done using tabular editor and calculation groups.

 

Check the blog post below about how you can achieve this:

https://www.sqlbi.com/articles/controlling-format-strings-in-calculation-groups/


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @PBI-Dash 

 

This can be done using tabular editor and calculation groups.

 

Check the blog post below about how you can achieve this:

https://www.sqlbi.com/articles/controlling-format-strings-in-calculation-groups/


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.