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
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!

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

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
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May 23 2022 episode 5 with aka link.jpg

The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt will talk about the importance of Data Modeling.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!