Forum Discussion
How to merge a dynamic column to a table
Hi all,
I have a database that's is updated daily. Every day a new column is added with the cumulative data.
I want to find a way to merge the latest column (the name of the column will match today()) with another table, so I always have the latest numbers of the day for each country.
Any ideas on how to do this?
Hello Anonymous
check out this solutions. The first approach is to select column Province and country and the last column (check out step GetProvinceCountryAndLastColumn ). The second approach calculates today date in format MM/DD/YY and then choose this column name instead of the last column. But I saw that the first may is written like 05-01-20 and so this logic would not work. (check step GetProvinceCountryAndTodayColumn).
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXICYlMgNjQAESCWkYFSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Province = _t, Country = _t, #"11/23/20" = _t, #"11/24/20" = _t, #"11/25/20" = _t, #"11/26/20" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Province", type text}, {"Country", type text}, {"11/23/20", type text}, {"11/24/20", type text}, {"11/25/20", type text}, {"11/26/20", type text}}), GetProvinceCountryAndLastColumn = Table.SelectColumns(#"Changed Type", {"Province","Country"}& {List.Last(Table.ColumnNames(#"Changed Type"))}), GetDay = if Text.Length(Text.From(Date.Day(DateTime.FixedLocalNow())))=2 then Text.From(Date.Day(DateTime.FixedLocalNow())) else "0"&Text.From(Date.Day(DateTime.FixedLocalNow())), GetMonth = if Text.Length(Text.From(Date.Month(DateTime.FixedLocalNow())))=2 then Text.From(Date.Month(DateTime.FixedLocalNow())) else "0"&Text.From(Date.Month(DateTime.FixedLocalNow())), GetYear = Text.End(Text.From(Date.Year(DateTime.FixedLocalNow())),2), CalculateTodayInFormatMMDDYY = GetMonth&"/"&GetDay&"/"&GetYear, GetProvinceCountryAndTodayColumn = Table.SelectColumns(#"Changed Type", {"Province","Country"}& {CalculateTodayInFormatMMDDYY}) in GetProvinceCountryAndTodayColumnCopy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
2 Replies
- Jimmy801
Community Champion
Hello Anonymous
check out this solutions. The first approach is to select column Province and country and the last column (check out step GetProvinceCountryAndLastColumn ). The second approach calculates today date in format MM/DD/YY and then choose this column name instead of the last column. But I saw that the first may is written like 05-01-20 and so this logic would not work. (check step GetProvinceCountryAndTodayColumn).
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXICYlMgNjQAESCWkYFSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Province = _t, Country = _t, #"11/23/20" = _t, #"11/24/20" = _t, #"11/25/20" = _t, #"11/26/20" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Province", type text}, {"Country", type text}, {"11/23/20", type text}, {"11/24/20", type text}, {"11/25/20", type text}, {"11/26/20", type text}}), GetProvinceCountryAndLastColumn = Table.SelectColumns(#"Changed Type", {"Province","Country"}& {List.Last(Table.ColumnNames(#"Changed Type"))}), GetDay = if Text.Length(Text.From(Date.Day(DateTime.FixedLocalNow())))=2 then Text.From(Date.Day(DateTime.FixedLocalNow())) else "0"&Text.From(Date.Day(DateTime.FixedLocalNow())), GetMonth = if Text.Length(Text.From(Date.Month(DateTime.FixedLocalNow())))=2 then Text.From(Date.Month(DateTime.FixedLocalNow())) else "0"&Text.From(Date.Month(DateTime.FixedLocalNow())), GetYear = Text.End(Text.From(Date.Year(DateTime.FixedLocalNow())),2), CalculateTodayInFormatMMDDYY = GetMonth&"/"&GetDay&"/"&GetYear, GetProvinceCountryAndTodayColumn = Table.SelectColumns(#"Changed Type", {"Province","Country"}& {CalculateTodayInFormatMMDDYY}) in GetProvinceCountryAndTodayColumnCopy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy- AnonymousNot applicable