March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello everybody,
i am having a problem which I cannot solve by myself.
I have a table that looks like this:
Date as month | Company Name | Score | Category |
March | A | 5 | x |
March | B | 4 | x |
April | A | 3 | y |
March | B | 5 | y |
March | C | 2 | x |
March | C | 2 | y |
April | A | 1 | x |
March | A | 3 | z |
And I need a table like this:
Company Name | March | April | Category |
A | 5 | x | |
B | 4 | x | |
A | 3 | y | |
B | 5 | y | |
C | 2 | x | |
C | 2 | y | |
A | 1 | x | |
A | 3 | z |
An alternative could also be:
Company Name | March average score | April average score |
A | 4 | 2 |
B | 4,5 | |
C | 2 |
If a new entry with a new month is included, a new column needs to be created with the name of the month
Is there a possibility to create these tables ?
Thank you for supporting me here.
Cheers,
Kai
Solved! Go to Solution.
Hey @Kaitra ,
that should be possible.
Mark the column [Date as month] and select pivot amd chose the score column for the values:
Afterwards you should have the desired result:
Here the full M-Code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k0sSs5Q0lFyBGJTIK5QitVBiDoBsQlc1LGgKDMHqtYYiCsx1JpiiDoDsRGGuTDRSgxzDTHUwmyrUoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date as month" = _t, #"Company Name" = _t, Score = _t, Category = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date as month", type text}, {"Company Name", type text}, {"Score", Int64.Type}, {"Category", type text}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[#"Date as month"]), "Date as month", "Score", List.Sum)
in
#"Pivoted Column"
Hey @Kaitra ,
that should be possible.
Mark the column [Date as month] and select pivot amd chose the score column for the values:
Afterwards you should have the desired result:
Here the full M-Code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k0sSs5Q0lFyBGJTIK5QitVBiDoBsQlc1LGgKDMHqtYYiCsx1JpiiDoDsRGGuTDRSgxzDTHUwmyrUoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date as month" = _t, #"Company Name" = _t, Score = _t, Category = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date as month", type text}, {"Company Name", type text}, {"Score", Int64.Type}, {"Category", type text}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[#"Date as month"]), "Date as month", "Score", List.Sum)
in
#"Pivoted Column"
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
89 | |
84 | |
70 | |
51 |
User | Count |
---|---|
206 | |
143 | |
97 | |
79 | |
68 |