Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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
Pedro | 15 | AS | JA |
Luis | 17 | AS | |
João | 16 | AS | JA |
Carlos | 18 | AS | |
Manuel | 15 | AS | JA |
from this table...
Name Age Code
Pedro | 15 | AS |
Pedro | 15 | JA |
Luis | 17 | AS |
João | 16 | AS |
João | 16 | JA |
Carlos | 18 | AS |
Manuel | 15 | AS |
Manuel | 15 | JA |
Anyone?
Thanks in advance
Best regards
Pedro
Solved! Go to Solution.
I created a calculated table for you like this:
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! 🙂
Proud to be a Super User!
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.
@Anonymous ,
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:
Finally, you will achieve the table.
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.
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
@Anonymous ,
Hi, please see the previous solution I have post.
Regards,
Jimmy Tao
I created a calculated table for you like this:
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! 🙂
Proud to be a Super User!
@Anonymous ,
In query editor, click on column [Code] then click Pivot using Values Column [Age] as below:
Then add two conditional columns as below:
Finally, remove column [JA] and rename column [AS] with [Age]:
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.
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
Hi @Anonymous
I've recreated your table like this:
In Query Editor, select column Code1 and Code 2 and hit Unpivot Columns in the Transform ribbon. This results in this:
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
Proud to be a Super User!
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
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
65 |
User | Count |
---|---|
135 | |
116 | |
101 | |
71 | |
61 |