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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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 @Anonymous ,

 

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
Anonymous
Not applicable

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

 

 

@Anonymous ,

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.

Hi @Anonymous ,

 

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

Anonymous
Not applicable

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

@Anonymous , 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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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