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
nlgenin
New 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.

 

So I have 151 windturbine tags and for each tag I need to have the dates from 01/01/2021 to today.

The dates will come from another table that has the min and max date;

 

In example it will be more clarified+

The table I need has to come out like this:

 

WinturbineDate
A020101/01/2021
A020101/02/2021
......
A020106/16/2021
A020201/01/2021
......
A020206/16/2021

 

So I already have a table with each windturbine tag

All I need to do is add the rows for the dates and fill down with the turbines tags.

 

 

Please help!!!

 

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community 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,

vxiaotang_1-1624435609195.png

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"

vxiaotang_4-1624435794717.png

result:

vxiaotang_3-1624435741474.png

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.

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community 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,

vxiaotang_1-1624435609195.png

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"

vxiaotang_4-1624435794717.png

result:

vxiaotang_3-1624435741474.png

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.

parry2k
Super User
Super User

@nlgenin you can add a new column in PQ like this 

{ [Min Date]..[Max Date] }

 

it will create a list and expand the list, you will get the all the dates for each tag.

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.