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
Sudharshan1919
Helper III
Helper III

Pivoting Error

Hey Hi Guys,

I am new to Power BI and facing some basic issues. Appreciate if anyone could help.

I have one issue at Pivoting the elements. I am calling this API ("https://management.azure.com/subscriptions/{Subscription}/providers/Microsoft.Compute/skus?api-versi...") and getting the data for listing out all the sizes of VMs in Azure and in this for one column i have a selected on some particular fields to be in my data. Now those are saved as rows and i need them as separate columns, I have tried Pivoting that column.. but the required data is getting "Error"

I am getting the data as below

Sudharshan1919_0-1639117198773.png

 


In the Column "value.capabilitiesname" i have selected only the below fields as per my requirement, the rest of them are hidden. After selecting the required fields i am getting the required data, but the other columns are getting duplicated. That means i have selected vCPU, MemoryGB, vCPUsAvailable, vCPUsPerCore and for every filed i am getting the data duplicacy of other columns. They are getting repeated for each of the filed i have selected.
So to get rid of those i have Pivoted the columns as below and getting the error if i select Don't Aggregate option while Pivoting.

Sudharshan1919_1-1639117198775.png

 

 

Sudharshan1919_2-1639117198517.png

 


As you can see below, i got the required format but the other data fields are in Error.

Sudharshan1919_3-1639117198781.png

 


Kindly help me and mention the step by step process to sort out from this issue.

Thanks,
Sudharshan.

1 ACCEPTED SOLUTION
Thingsclump
Resolver V
Resolver V

Hi @Sudharshan1919 

 

Here you go if you want to do it PQ. the trick is you have to tell PQ that every 4 rows should be treated as a single row after pivoting. so I have added index,divide and round up. use the code that i have pasted at last.

 

Thingsclump_0-1639130730842.png

 

 

Thingsclump_1-1639130730645.png

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsssKilNzPFNTM7IzEstVtJRcjQEEmXOAaEgjqFSrA5ORb6puflFlSBVeuam+BSCTUssS8zMSUzKSSVkLEh1cEFqUXJ+EVFqQRwjotxpRKo78RqL5k6g2lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [resourcetype = _t, valuename = _t, capabilitiesname = _t, capabilityvalue = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"resourcetype", type text}, {"valuename", type text}, {"capabilitiesname", type text}, {"capabilityvalue", type number}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Inserted Modulo" = Table.AddColumn(#"Added Index", "Modulo", each Number.Mod([Index], 4), type number),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Modulo",{"Modulo"}),
#"Divided Column" = Table.TransformColumns(#"Removed Columns", {{"Index", each _ / 4, type number}}),
#"Rounded Up" = Table.TransformColumns(#"Divided Column",{{"Index", Number.RoundUp, Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Rounded Up", List.Distinct(#"Rounded Up"[capabilitiesname]), "capabilitiesname", "capabilityvalue")
in
#"Pivoted Column"

 

 

 

Thanks,

thingsclump

www.thingsclump.com 

 

accpet solution if this works for you.

View solution in original post

6 REPLIES 6
Thingsclump
Resolver V
Resolver V

Hi @Sudharshan1919 

 

Here you go if you want to do it PQ. the trick is you have to tell PQ that every 4 rows should be treated as a single row after pivoting. so I have added index,divide and round up. use the code that i have pasted at last.

 

Thingsclump_0-1639130730842.png

 

 

Thingsclump_1-1639130730645.png

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsssKilNzPFNTM7IzEstVtJRcjQEEmXOAaEgjqFSrA5ORb6puflFlSBVeuam+BSCTUssS8zMSUzKSSVkLEh1cEFqUXJ+EVFqQRwjotxpRKo78RqL5k6g2lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [resourcetype = _t, valuename = _t, capabilitiesname = _t, capabilityvalue = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"resourcetype", type text}, {"valuename", type text}, {"capabilitiesname", type text}, {"capabilityvalue", type number}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Inserted Modulo" = Table.AddColumn(#"Added Index", "Modulo", each Number.Mod([Index], 4), type number),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Modulo",{"Modulo"}),
#"Divided Column" = Table.TransformColumns(#"Removed Columns", {{"Index", each _ / 4, type number}}),
#"Rounded Up" = Table.TransformColumns(#"Divided Column",{{"Index", Number.RoundUp, Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Rounded Up", List.Distinct(#"Rounded Up"[capabilitiesname]), "capabilitiesname", "capabilityvalue")
in
#"Pivoted Column"

 

 

 

Thanks,

thingsclump

www.thingsclump.com 

 

accpet solution if this works for you.

AllisonKennedy
Super User
Super User

@Sudharshan1919 

 

Why do you need them in columns? You can use the 'Matrix' visual to do the pivoting for you (don't usually recommend doing this in Power Query). This article is for Excel, but applies to Power BI data tables too: https://www.myonlinetraininghub.com/excel-tabular-data-format 

 

In order to see more info on the error, click in the cell that says 'Error', but do NOT click on the link Error. You'll see a message at the bottom of the table explaining what the error is.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hey.. Hi @AllisonKennedy 

 

I am aware about the Matrix Visual.. here i need to join this table with another by making a relationship. So when making the relationship and adding Matrix  the Visual Par seemed not good and it was the confusing thing to understand when we see the visual part.

 

Below is my table and the when i join the VM Sizes Table with my below one, it must show the Features of VM that i mentioned in 1st post.

 

4.png

Now when adding the matrix it is looking like below and i have also tried several other tricks by alternating the rows and columns in the Visualization editor option, even though it not worked.

Sudharshan1919_2-1639121515127.png

4.png

When i am adding the VM Sizes table fields here, i am not getting the required data.. it is either getting to be selected First or last only

Sudharshan1919_3-1639122841059.png

 

Sudharshan1919_4-1639122905621.png

 

Thanks

@Sudharshan1919  Can you provide sample data and a picture of the end result you want please?

 

The SELECTEDVALUE function in DAX may help get you the info you need in the VALUES section of the matrix (rather than being stuck with 'first' and 'last').

 

Also, did you check what the error message said in Power Query? We can't help troubleshoot without knowing what the error is.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hello @AllisonKennedy ,

Got response from @Thingsclump and he solved my requirement. Please refer to his reply in this thread.

 

Thanks

@Sudharshan1919  Please accept his @Thingsclump 's post as solution so that we all know this is solved and don't spend unnecessary time on it, but also so others with similar issue can find it easier.

 

Glad you got it solved. 😀


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.