Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be 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

Reply
Kaitra
Frequent Visitor

Table transformation based on dynamic entries

Hello everybody,

 

i am having a problem which I cannot solve by myself.

 

I have a table that looks like this:

Date as monthCompany NameScoreCategory
MarchA5x
MarchB4x
AprilA3y
MarchB5y
MarchC2x
MarchC2y
AprilA1x
MarchA3z

 

And I need a table like this:

 

Company NameMarchAprilCategory
A5 x
B4 x
A 3y
B5 y
C2 x
C2 y
A 1x
A3 z

 

An alternative could also be:

Company NameMarch average scoreApril average score
A42
B4,5 
C2 

 

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

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @Kaitra ,

 

that should be possible.

Mark the column [Date as month] and select pivot amd chose the score column for the values:

selimovd_0-1618827602554.png

 

Afterwards you should have the desired result:

selimovd_1-1618827627274.png

 

 

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"

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

1 REPLY 1
selimovd
Super User
Super User

Hey @Kaitra ,

 

that should be possible.

Mark the column [Date as month] and select pivot amd chose the score column for the values:

selimovd_0-1618827602554.png

 

Afterwards you should have the desired result:

selimovd_1-1618827627274.png

 

 

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"

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.