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
saritart1
Frequent Visitor

reshape

Hello Everyone,

 

I am having a problem with my reshape. Currently, I have the data as the picture 1 shows.  I want to have it as Picture 2.

That is, I want it to be uniquely identified by "codigo_participante" and to have multiple columns derivated from "Valor". I will really aprreciate if you could help me. 

I tried using "Pivot" but I just can see the UnPivot Column, no the Pivot one.

 

Thank you in advance.

 

 

Picture 1Picture 1Picture 2Picture 2

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @saritart1 ,

 

Pivot operation need at least two fields(category and value), I'd like to suggest you add a custom column to store count of valor, then do pivot on valor and count fields.

 

Full Query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1MFDSUVKK1QGyDQwMkdhGQHaAX6gLMt8xJzkxJyUzMd45MScTImFoZAGUcM1NSsxKTEmMDy5NTc5MRJZCmAHhYzHDwNICbrEx2EEY5sUCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Code = _t, Valor = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Valor", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Count", each if [Valor] <> "" then 1 else null),
    #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Valor]), "Valor", "Count", List.Sum),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{""})
in
    #"Removed Columns"

2.png

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @saritart1 ,

 

Pivot operation need at least two fields(category and value), I'd like to suggest you add a custom column to store count of valor, then do pivot on valor and count fields.

 

Full Query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1MFDSUVKK1QGyDQwMkdhGQHaAX6gLMt8xJzkxJyUzMd45MScTImFoZAGUcM1NSsxKTEmMDy5NTc5MRJZCmAHhYzHDwNICbrEx2EEY5sUCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Code = _t, Valor = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Valor", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Count", each if [Valor] <> "" then 1 else null),
    #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Valor]), "Valor", "Count", List.Sum),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{""})
in
    #"Removed Columns"

2.png

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.