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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
harshadrokade
Post Partisan
Post Partisan

unpivot columns changing field Data type

Hi,

 

I have data as below-

 

Student nameYearParameterAParameterBParameterCParameterD
A202122%9910%67
B202134%8929%78

 

Parameter A & C is % fields & Parameter B & D are whole numbers

 

As I want to create a column chart with Subject values provided in slicer, I had to unpivot the data & the new data looks like below-

 

Student nameYearAttributeValue
A2021ParameterA22
A2021ParameterB99
A2021ParameterC10
A2021ParameterD67
B2021ParameterA34
B2021ParameterB89
B2021ParameterC29
B2021ParameterD78

 

Now all values have come under 1 column as 'Value' & so I lost the formatting of the value like percentage & number.

 

Now If I use this value column in column chart, it shows the percentage values like a normal number value however when I used to create column chart with old table coumns (without unpivot), the percentage fields were being shown with % sign in chart as those were kept with data type as %.

 

Now how to handle this case where if someone selects parameter A & C in slicer, the column chart shoudl show their values as % & when other paramters selected, those to be shown as normal number values.

 

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Using this M code, i have been able to transform the structure to th eone that you see in the image below

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIyMDIEUUaqQNLSEkgYGoCYZuZKsTrRSk4IJcYmIHELkBIjSxDT3EIpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Student name" = _t, Year = _t, ParameterA = _t, ParameterB = _t, ParameterC = _t, ParameterD = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Student name", type text}, {"Year", Int64.Type}, {"ParameterA", Percentage.Type}, {"ParameterB", Int64.Type}, {"ParameterC", Percentage.Type}, {"ParameterD", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Student name", "Year"}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each if [Attribute]="ParameterA" or [Attribute]="ParameterC" then 1 else 2),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Added Custom", {{"Custom", type text}}, "en-IN"), List.Distinct(Table.TransformColumnTypes(#"Added Custom", {{"Custom", type text}}, "en-IN")[Custom]), "Custom", "Value"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"1", Percentage.Type}})
in
    #"Changed Type1"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks @Ashish_Mathur . My requirement is I want all the values to be coming in single column as I will be using the same column in my column chart on Y axis. If i keep 2 columns, I cant use multiple columns on Y axis. I think I will have to write a measure like if I select a specific paramater in slicer, then the value column will be formatted to % or else it will be shown as number. Then I will use this measure on my Y axis of column chart.

Hi,

I think you need to use the new (unreleased) "Field Parameter" feature.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@harshadrokade , Unpivot the table in Power query

 

https://radacad.com/pivot-and-unpivot-with-power-bi

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak Thanks Amit. I did unpivot in power query only. The problem is when i do the same, the value format of the different parameters gets chnaged. How to bring it to the original format. May be a measure will help here but unable to get how to do the same.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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