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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
palmeirense_
Frequent Visitor

Format loss when unpivoting columns

I am working on a report where in the source file, I have a set of columns expressed in different format types (a few are percentages, some are currency, others are fixed decimal number).

Because my end users should be able to slice my visuals by the values in a single column, I had to unpivot columns, however, when doing that, I lose all that formatting. How can I get around this issue?

Thanks!

8 REPLIES 8
v-angzheng-msft
Community Support
Community Support

Hi, @palmeirense_ 

You can use Switch function and format function to help you
When you unpivot the columns, you get an attribute column.
Create a measure like below

_Switch = 
SWITCH(
    SELECTEDVALUE('Table'[Attribute]),
    "Percentage",FORMAT(SELECTEDVALUE('Table'[Value]),"Percent"),//columnName1
    "Currency", FORMAT(SELECTEDVALUE('Table'[Value]),"Currency"),//columnName2
    "Decimal number", FORMAT(SELECTEDVALUE('Table'[Value]),"Fixed"))//columnName3

Result:

vangzhengmsft_1-1648693921755.png

Please refer to the attachment below for details.

Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

edhans
Super User
Super User

If the unpivoted columns do not share the same data type it will revert to any, or ABC/123. You just need to change the type after the unpivot operation, then change or confirm the format in Power BI. 

Note that data type and format are not the same. You can have it a a currency data type, but still format it as a percent, whole number, etc. in the report layer. But it is important to set the data type in Power Query.



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

Apologies as I might not have explained this very well.

In my first power query step, I have 5 columns which get unpivoted into only 1 column. I can change formats for this resulting column but I want to be able to have different data types depending on the row value. Is that possible?

No. Each column can only have one data type, or it can be a variant, where it is whatever, but that will always look like text to Power BI and is a mess. 

Don't combine data types into a single column. It might be helpful to explain what you are doing, but putting units, dollars, percents, and text into a single column via Unpivot in Power BI is very likely not the right way to go.



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

In my report, I have a line chart showing trended metrics on a monthly basis. My hope was, the user could pick which metric they want to trend out from a slicer and if it's dollars per unit, it would show up as currency, if it's share, it would show as a percentage, etc. Maybe I'll explore a different way of showing that

Use a SWITCH measure. See Write Conditional Statement Using SWITCH in DAX and Power BI - RADACAD for guidance.

You could also use a Calculation Group, but that is next level. A SWITCH measure is the cleanest and quickest to implement. Only explore CG's if the performance is not acceptable.



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

I tried SWITCH but is there a way to maintain different formatting options within that expression? I couldn't figure it out

See this article. 
Dynamic Formatting of Switch Measures in Power BI 💡 - Excelerator BI

or use Calcuation Groups, which can use dynamic formatting and retain numeric formats. But you'd need to reveiw the entire SQL BI series on CG's before using them. Calculation Groups - SQLBI



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

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Kudoed Authors