cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mag22
Frequent Visitor

Concatenate rows using ids

Hi, I'm a bit new to power bi so unsure how to achieve this. I have data broken into sections that I want to combine together based on an id value for the rows. I've shown what the data looks like and what I want it to look like. Any help would be appreciated, thank you!Issue.PNG

1 ACCEPTED SOLUTION

Hi @mag22 ,

 

Please copy this code and paste it to the advanced editor and follow the steps:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjJU0lECoVidaCWXxJJUINvAUB+IjAyMDKEcIwgHpMQRKAQSNgHznIAsIyA2BfOcgSxjIDYD84KMsJtsjGyyCckmxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Column2] <> "")),
    Custom1 = Table.Split(#"Filtered Rows",4),
    Custom2 = List.Transform(Custom1, each Table.UnpivotOtherColumns(Table.PromoteHeaders(_), {"Date"}, "Attribute", "Value")),
    Custom3 = Table.Combine( Custom2 ),
    #"Pivoted Column" = Table.Pivot(Custom3, List.Distinct(Custom3[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

 

 

Assuming that all your sets have the same length and members (A, B, C) like you stated in your example.

This is quite a common task and you might find other approaches to do it if you search for "unstacking".

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

5 REPLIES 5
mag22
Frequent Visitor

Hi @amitchandak, thanks for the quick response. Yes unfortunately it isn't the best data. It is sorted by roster period so the first set of dates is roster 1, second set is roster 2, etc. but they are all structured the same. I've attached a slightly more accurate representation of the data as it is entered into power bi.

 

I'm afraid I don't quite know what you mean by copying remove rows. Ideally I'd like to do this dynamically where when a new roster period is added, the data once again rearranges itself accurately. Thanks again for your help.

mag22_0-1629352471959.png

 

 

@mag22 ,

I think advice need from M expert. 

let see @ImkeF  can off some help

 

Table.Split and Table.SplitAt are some options, but that will be limited by page size or rows.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

Hi @mag22 ,

 

Please copy this code and paste it to the advanced editor and follow the steps:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjJU0lECoVidaCWXxJJUINvAUB+IjAyMDKEcIwgHpMQRKAQSNgHznIAsIyA2BfOcgSxjIDYD84KMsJtsjGyyCckmxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Column2] <> "")),
    Custom1 = Table.Split(#"Filtered Rows",4),
    Custom2 = List.Transform(Custom1, each Table.UnpivotOtherColumns(Table.PromoteHeaders(_), {"Date"}, "Attribute", "Value")),
    Custom3 = Table.Combine( Custom2 ),
    #"Pivoted Column" = Table.Pivot(Custom3, List.Distinct(Custom3[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

 

 

Assuming that all your sets have the same length and members (A, B, C) like you stated in your example.

This is quite a common task and you might find other approaches to do it if you search for "unstacking".

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

mag22
Frequent Visitor

Thank you so much! I was able to use your code to make it work with my data dynamically it seems. Cheers!

amitchandak
Super User
Super User

@mag22 , Not great data to have.

create copy data.

Copy one remove rows after. Copy 2 remove rows after  (second date row)

 

Append the two data .

 

 

We can check with M expert too

@ImkeF , best ways to deal with this data

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.