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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Transposing table with null values

 

Is it possible to achive transposing the table like below with null values? I've tried clicking on "Transpose" in Power query and it's not transforming the way I want.. any help would be appreciated!! 

 

yham1023_1-1672788002722.png

 

 

 

DeptID Directors_mathDirectors_sci
111nullHaley
111nullJamie
111nullLee
222AmyKJenny
222AmyKSam

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

You can try this. I have attached a sample file at bottom. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ0VNJRyivNyQFSHok5qZVKsTpowl6JuZmpmMI+qRBBIyMjIM8xt9IbpDY1L68SUzg4MVcpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"DeptID " = _t, Directors_math = _t, Directors_sci = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DeptID ", Int64.Type}, {"Directors_math", type text}, {"Directors_sci", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"DeptID "}, {{"Directors_math", each [Directors_math], type nullable list}, {"Directors_sci", each [Directors_sci], type nullable list}}),
    #"Extracted Values" = Table.TransformColumns(#"Grouped Rows", {"Directors_math", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
    #"Extracted Values1" = Table.TransformColumns(#"Extracted Values", {"Directors_sci", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values1", "Directors_math", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Directors_math.1", "Directors_math.2", "Directors_math.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Directors_math.1", type text}, {"Directors_math.2", type text}, {"Directors_math.3", type text}}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type1", "Directors_sci", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Directors_sci.1", "Directors_sci.2", "Directors_sci.3"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Directors_sci.1", type text}, {"Directors_sci.2", type text}, {"Directors_sci.3", type text}})
in
    #"Changed Type2"

vjingzhang_0-1672796165556.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it. Highly appreciate your Kudos!

View solution in original post

2 REPLIES 2
wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1672796506662.png

= let a=Table.ColumnNames(Source) in Table.Combine(Table.Group(Source,"DeptID ",{"n",each #table({a{0}}&List.TransformMany(List.Skip(a),(x)=>List.Positions([#"DeptID "]),(x,y)=>x&"_"&Text.From(y+1)),{{[#"DeptID "]{0}}&List.Combine(List.Skip(Table.ToColumns(_)))})})[n])

 

v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

You can try this. I have attached a sample file at bottom. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ0VNJRyivNyQFSHok5qZVKsTpowl6JuZmpmMI+qRBBIyMjIM8xt9IbpDY1L68SUzg4MVcpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"DeptID " = _t, Directors_math = _t, Directors_sci = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DeptID ", Int64.Type}, {"Directors_math", type text}, {"Directors_sci", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"DeptID "}, {{"Directors_math", each [Directors_math], type nullable list}, {"Directors_sci", each [Directors_sci], type nullable list}}),
    #"Extracted Values" = Table.TransformColumns(#"Grouped Rows", {"Directors_math", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
    #"Extracted Values1" = Table.TransformColumns(#"Extracted Values", {"Directors_sci", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values1", "Directors_math", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Directors_math.1", "Directors_math.2", "Directors_math.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Directors_math.1", type text}, {"Directors_math.2", type text}, {"Directors_math.3", type text}}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type1", "Directors_sci", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Directors_sci.1", "Directors_sci.2", "Directors_sci.3"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Directors_sci.1", type text}, {"Directors_sci.2", type text}, {"Directors_sci.3", type text}})
in
    #"Changed Type2"

vjingzhang_0-1672796165556.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it. Highly appreciate your Kudos!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.