Forum Discussion
Merging / appending to keep all
- 1 year ago
Hi j1s, I recommend Table.Join function for this purpose:
Output
let Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kvMTVUwVNJRgiNDpVgdqLgRTARMGSEkjJE1IIRNoIoNMUwyxWWSGaoWhIQ5disskNQboshYYtdgaIBitVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Full Name" = _t, #"2024-11-25" = _t, #"2024-12-02" = _t, #"2024-12-09" = _t, #"2024-12-16" = _t]), Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kvMTVUwVNJRAiI4FasDlTCCiBhDJY0QMsYQGQwdJkiCQAoubooQRJUwQ7UCyShzhAyq3RaoZiFpscSlxdAApx5DCwOcuiwMMbTFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Full Name" = _t, #"2025-01-01" = _t, #"2025-01-08" = _t, #"2025-01-15" = _t, #"2025-01-22" = _t]), T2_RenamedColumn = Table.RenameColumns(Table2,{{"Full Name", "Full Name2"}}), Merged = Table.Join(Table1, "Full Name", T2_RenamedColumn, "Full Name2", JoinKind.FullOuter), ReplacedFullName = Table.ReplaceValue(Merged, each [Full Name] is null, each [Full Name2], (x,y,z)=> if y then z else x, {"Full Name"} ), RemovedColumns = Table.RemoveColumns(ReplacedFullName,{"Full Name2"}) in RemovedColumns - 1 year ago
Sorting the columns is not that easy, because your column names are text and we need a date sort.
But this works:
let #"Unpivoted Table1" = Table.UnpivotOtherColumns(Table1, {"Full Name"}, "Attribute", "Value"), #"Unpivoted Table2" = Table.UnpivotOtherColumns(Table2, {"Full Name"}, "Attribute", "Value"), #"Unpivoted Table3" = Table.UnpivotOtherColumns(Table3, {"Full Name"}, "Attribute", "Value"), #"Unpivoted ALL"= Table.Combine({#"Unpivoted Table1",#"Unpivoted Table2",#"Unpivoted Table3"}), #"Added Custom" = Table.AddColumn(#"Unpivoted ALL", "Dates", each [Attribute]), #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Dates", type date}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Attribute", "Dates"}, {{"Count", each Table.RowCount(_), Int64.Type}}), #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Dates", Order.Ascending}}), #"Pivoted Column" = Table.Pivot(#"Unpivoted ALL", List.Distinct(#"Unpivoted ALL"[Attribute]), "Attribute", "Value", List.Sum), #"Reordered Columns" = Table.ReorderColumns(#"Pivoted Column",#"Sorted Rows"[Attribute]) in #"Reordered Columns"Producing this:
About the missing dates: I suspect this will not be a problem in real life.
But if it is:
- create a table with all possible dates, for exapmple by querying the dat range in the orignal dataset
- Transpose the table
- Use Forst Row as Headers
- And if needed, remove all rows with a Table.SelectRows(#"Promote Headers", each false)
- and then do a Table.Union of this table with the pivoted table
I doubt this will be worth the trouble ....
Did I answer your question? Then please (also) mark my post as a solution and make it easier to find for others having a similar problem.
Remember: You can mark multiple answers as a solution...
If I helped you, please click on the Thumbs Up to give Kudos.Kees Stolker
A big fan of Power Query and Excel
Hi j1s
Thank you for reaching out microsoft fabric community forum.
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
- j1s1 year agoHelper I
Anonymous there are apparently more than one solution, and I can't make any of them as the solution until I have seen all of them. Apparently there was another posted, which I was notified about by email but for some reason (any idea?) is not visible (to me) here.
This is the email
From: Fabric Community Administrator <[email protected]> Date: Sun, 23 Feb 2025 at 12:03 Subject: SundarRaj mentioned you in Microsoft Fabric Community To: j1s Hi j1s, SundarRaj (Frequent Visitor) mentioned you in a post! Join the conversation below: Re: Merging / appending to keep all Hi @j1s . Here's another way to approach your query. I'll share two images, one of the ouput and the other of the M code used. In this approach, 1. Remove the first column in each table (to make it dynamic you can use a List.Transform to remove the text columns) and use Table.ToColumns 2. Combine the lists of list created in each table and create one single list containing the contents of both the table 3. Use Table.ColumnNames on both the table and combine them again in a list format. 4. Last step is the to simply use Table.FromColumns and convert them into a Table using ColumnNames to generate the headers as well.Untill I can see the pictures referred to, I'm not sure how to understand if it is the solution
- Anonymous1 year agoNot applicable
Hi j1s
Could you please let us know if your issue has been resolved? Did any of the solutions meet your expectations?If so, please mark the helpful reply and accept it as the solution. This will help other community members with similar problems to solve them faster.
Thank you.
- j1s1 year agoHelper I
Anonymous wrote:Hi j1s
Could you please let us know if your issue has been resolved? Did any of the solutions meet your expectations?If so, please mark the helpful reply and accept it as the solution. This will help other community members with similar problems to solve them faster.
Thank you.
Hello Anonymous , How do I mark several responses as solutions?