Forum Discussion
nlgenin
5 years agoNew Member
Creating a table with dynamic dates and one variable per date
Hello, everyone. I need your kind help to create a crazy table in PowerQuery M. What I need to do is create a table with dynamic dates range and replicate these dates for each windturbine tag. ...
- 5 years ago
Hi nlgenin
do you mean you want to create the table like bellow with M code?
Name Date A1 2021/1/1 A1 2021/1/2 A1 2021/1/3 A1 2021/1/4 A1 2021/1/5 A1 . A1 . A1 . A1 . A1 2021/6/23 A2 2021/1/1 A2 2021/1/2 A2 2021/1/3 A2 2021/1/4 A2 2021/1/5 A2 . A2 . A2 . A2 . A2 2021/6/23 -
here are my operations,
Then open the Advanced Editor, and paste the M code bellow into it
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRUitWhnDKimIoFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}}), #"Removed Duplicates" = Table.Distinct(#"Changed Type"), diffday=Int16.From( Date.From(DateTime.LocalNow()) - Date.From(#date(2021,1,1)))+1, #"Added Custom" = Table.AddColumn(#"Removed Duplicates", "Custom", each List.Dates(#date(2021, 1, 1), diffday, #duration(1, 0, 0, 0))), #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom") in #"Expanded Custom"result:
See sample file attached bellow.
Best Regards,
Community Support Team _ Tang
If this post helps, please consider Accept it as the solution✔️ to help the other members find it more quickly.
v-xiaotang
5 years agoCommunity Support
Hi nlgenin
do you mean you want to create the table like bellow with M code?
| Name | Date |
| A1 | 2021/1/1 |
| A1 | 2021/1/2 |
| A1 | 2021/1/3 |
| A1 | 2021/1/4 |
| A1 | 2021/1/5 |
| A1 | . |
| A1 | . |
| A1 | . |
| A1 | . |
| A1 | 2021/6/23 |
| A2 | 2021/1/1 |
| A2 | 2021/1/2 |
| A2 | 2021/1/3 |
| A2 | 2021/1/4 |
| A2 | 2021/1/5 |
| A2 | . |
| A2 | . |
| A2 | . |
| A2 | . |
| A2 | 2021/6/23 |
-
here are my operations,
Then open the Advanced Editor, and paste the M code bellow into it
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRUitWhnDKimIoFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}}),
#"Removed Duplicates" = Table.Distinct(#"Changed Type"),
diffday=Int16.From( Date.From(DateTime.LocalNow()) - Date.From(#date(2021,1,1)))+1,
#"Added Custom" = Table.AddColumn(#"Removed Duplicates", "Custom", each List.Dates(#date(2021, 1, 1), diffday, #duration(1, 0, 0, 0))),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
in
#"Expanded Custom"
result:
See sample file attached bellow.
Best Regards,
Community Support Team _ Tang
If this post helps, please consider Accept it as the solution✔️ to help the other members find it more quickly.