Forum Discussion
How to merge a dynamic column to a table
- 5 years ago
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
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
GetProvinceCountryAndTodayColumn
Copy 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