cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

power query transpose

Hi guys

I'm trying to transpose this table but i can't do that. Maybe i'm not looking well.

Can you guys give me help?

The idea is to have this result...

Name           Age      Code1  Code2

Pedro15ASJA
Luis17AS 
João16ASJA
Carlos18AS 
Manuel15ASJA

 

from this table...

 

Name          Age      Code

Pedro15AS
Pedro15JA
Luis17AS
João16AS
João16JA
Carlos18AS
Manuel15AS
Manuel15JA

 

Anyone?

Thanks in advance

Best regards

Pedro

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User I
Super User I

Re: power query transpose

I created a calculated table for you like this:

image.png

NewTable = 
VAR names = DISTINCT('Table'[Name])
RETURN
ADDCOLUMNS(
    SELECTCOLUMNS(names, "Names", [Name]), 
    "Age", CALCULATE(AVERAGE('Table'[Age]), FILTER('Table', 'Table'[Name] = [Names])),
    "Code1", IF(CONTAINS('Table', 'Table'[Name], [Names], 'Table'[Code], "AS"), "AS", BLANK()),
    "Code2", IF(CONTAINS('Table', 'Table'[Name], [Names], 'Table'[Code], "JA"), "JA", BLANK())
)

If this doesn't work in your case, please explain in detail how PowerBI should know what value should be in Code1 and Code2 value. 

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





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

Proud to be a Super User!




View solution in original post

9 REPLIES 9
Highlighted
Super User I
Super User I

Re: power query transpose

Hi @pedromooji 

 

I've recreated your table like this:

image.png

In Query Editor, select column Code1 and Code 2 and hit Unpivot Columns in the Transform ribbon. This results in this:

image.png

Remove column Attribute and filterout the blanks in column Value and you have your desired result.

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂

Kind regards

Djerro123

 





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

Proud to be a Super User!




Highlighted
Community Support
Community Support

Re: power query transpose

@pedromooji ,

 

In query editor, click on column [Code] then click Pivot using Values Column [Age] as below:

1.PNG 

 Then add two conditional columns as below:

2.PNG3.PNG

 

Finally, remove column [JA] and rename column [AS] with [Age]:

4.PNG 

 

Community Support Team _ Jimmy Tao

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

Highlighted
Helper V
Helper V

Re: power query transpose

Hi @JarroVGIT 

Thanks for trying to help me but....when you say "i've recreated your table..." this is how i'd like the result to be, you know? Maybe i wasn't explicit enough. So sorry about it.
I can't have any duplicates on names and i have to see for each name if there's an AS or a JA or both...like the table you've recreated.

Can you help anyhow? Thank you so much.
Pedro

Highlighted
Helper V
Helper V

Re: power query transpose

Hi @v-yuta-msft 

Thank you very much for your reply but your solution starts with my desired solution....
Could you please think of a way of doing it, from my original table, from the 2nd table?

Thank you so much

Pedro

Highlighted
Community Support
Community Support

Re: power query transpose

@pedromooji ,

 

That's much more simple. Click on column Code1 and Code2, then click Transform-> Unpivot Columns. Remove and Attribute column and rename Value column with "Code". Then remove the blank value in the Code column using filter as below:

Capture.PNG 

 

Finally, you will achieve the table.

2.PNG 

 

Community Support Team _ Jimmy Tao

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

Highlighted
Helper V
Helper V

Re: power query transpose

Hey @v-yuta-msft 

I'm very sorry to say but you got it all wrong. The final solution that you've presented is what i have now, and what i want to transform. Could you please read my original/first message. You'll understand what i need...

Thank you so much for your effort

Highlighted
Super User I
Super User I

Re: power query transpose

I created a calculated table for you like this:

image.png

NewTable = 
VAR names = DISTINCT('Table'[Name])
RETURN
ADDCOLUMNS(
    SELECTCOLUMNS(names, "Names", [Name]), 
    "Age", CALCULATE(AVERAGE('Table'[Age]), FILTER('Table', 'Table'[Name] = [Names])),
    "Code1", IF(CONTAINS('Table', 'Table'[Name], [Names], 'Table'[Code], "AS"), "AS", BLANK()),
    "Code2", IF(CONTAINS('Table', 'Table'[Name], [Names], 'Table'[Code], "JA"), "JA", BLANK())
)

If this doesn't work in your case, please explain in detail how PowerBI should know what value should be in Code1 and Code2 value. 

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





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

Proud to be a Super User!




View solution in original post

Highlighted
Community Support
Community Support

Re: power query transpose

@pedromooji ,

 

Hi, please see the previous solution I have post.

 

Regards,

Jimmy Tao

Highlighted
Super User IV
Super User IV

Re: power query transpose

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkhNKcpX0lEyNAUSjsFKsTpoYl6OYDGf0sxikJA5QplX/uHFYGVmOMSgWp0Ti3LywZotEAp9E/NKU3PQLEYVBGmPBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, Age = _t, Code = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Age", Int64.Type}, {"Code", type text}}),
    Partition = Table.Group(#"Changed Type", {"Name"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Age", "Code", "Index"}, {"Age", "Code", "Index"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Partition", "Custom", each "Code "&Number.ToText([Index])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom]), "Custom", "Code")
in
    #"Pivoted Column"

Hope this helps.

Untitled.png


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

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors