Forum Discussion
Jpalaci1
Oct 01, 2021Brass Contributor
Power Query: Duplicate Rows, MONTH(TODAY()), and Add to Month For Duplicated Rows
I successfully transformed my data in Power Query and in the steps to get the data almost to where I need it. I'd like to take step 1a, step 2, and step 3 and put it into a final output in step ...
- Oct 01, 2021
Oops, forgot to check if we are in December duplication is not required. As variant you may add if ... then ... else.
NicolasTld
Oct 01, 2021Copper Contributor
Hello Jpalaci1 !
Step 1 :
- Filter 1 :
- I recommend you to add TODAY() formula in a cell in your worksheet. Then, load this range in Power Query (Select your cell, click on "Data" > "From table"). Today date will be now loaded into Power Query.
- To use it properly, you will have to add "{0}[Column1]" (drill down) to get a value and not a table. It should look like this "Date.From(Excel.CurrentWorkbook(){[Name="Today_date"]}[Content]{0}[Column1])".
- Rename it "Today_date" and use this date for your filter > Table.SelectRows(Step, each [Month]>= Date.Month(Today_date))
- Filter 2 :
- Use Date.Month(Today_date) to help you perform this filter
Step 2 & 3 :
- Step 2 :
- if you want to duplicate rows for each month, you can create for each row a list which contains month number from month +1 to 12. Example : {1..12} creates a list from 1 to 12.
- You can use "AddColumn = Table.AddColumn(PreviousStep, "List", each {[Month]+1..12})". You will have a list from Month +1 to 12 in each Row.
- Then, Expand this new column by using "ExpandColumn = = Table.ExpandListColumn(AddColumn, "List").
- Step 3 :
- I don't understand what you would like to do. You can use the same list creation as explained in step 2 to duplicate rows (with {1..12}).
In order to append step 1a, step 2 and step 3 into one table, you can simply use Table.Combine (more info here : https://docs.microsoft.com/fr-fr/powerquery-m/table-combine)
Step4 = Table.Combine({"Step1", "Step2", "Step3")}
Hope it will help,
Nicolas
- Jpalaci1Oct 06, 2021Brass ContributorThank you for the help. This helped!
- NicolasTldOct 06, 2021Copper ContributorWith pleasure !
You should better use "Date.From( DateTime.LocalNow() )" as Sergei proposed instead of load a named range with TODAY formula. I forgot this function
Have a nice day 🙂
Nicolas