M code Date.StartOfMonth where should is go?

dicken

Active Member
Joined
Feb 12, 2022
Messages
283
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a lsit of a list of dates produced by uisng ;

Power Query:
Table.AddColumn(#"Changed Type", "Custom", each 
List.Transform(
 { Number.From( [#"Sart Date "])..Number.From([End Date] )}, (_)=> Date.From(_) ) )

the output of which is :
but I need the dates is the lists to be the start of the moth, but can't get it right as to where Date.StartOfMonth should be placed , I just keep getting errors.
1659274497811.png


Richard
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Here's an example you can adjust to fit:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
    tbl = Table.TransformColumnTypes(Source,{{"Start", type date}, {"End", type date}}),
    Result = Table.AddColumn(tbl, "Custom", each List.Generate(()=> Date.StartOfMonth([Start]), (x)=> x<=[End], (x)=> Date.AddMonths(x ,1))),
    ShowList = Table.TransformColumns(Result, {{"Custom", each Text.Combine(List.Transform(_, Text.From),", ")}})
in
    ShowList

PQ example.xlsx
ABCD
1StartEnd
21/1/20225/21/2022
32/3/20213/4/2022
43/5/20223/23/2022
5
6StartEndCustom
71/1/20225/21/20221/1/2022, 2/1/2022, 3/1/2022, 4/1/2022, 5/1/2022
82/3/20213/4/20222/1/2021, 3/1/2021, 4/1/2021, 5/1/2021, 6/1/2021, 7/1/2021, 8/1/2021, 9/1/2021, 10/1/2021, 11/1/2021, 12/1/2021, 1/1/2022, 2/1/2022, 3/1/2022
93/5/20223/23/20223/1/2022
10
Sheet4
 
Upvote 0
Here's an example you can adjust to fit:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
    tbl = Table.TransformColumnTypes(Source,{{"Start", type date}, {"End", type date}}),
    Result = Table.AddColumn(tbl, "Custom", each List.Generate(()=> Date.StartOfMonth([Start]), (x)=> x<=[End], (x)=> Date.AddMonths(x ,1))),
    ShowList = Table.TransformColumns(Result, {{"Custom", each Text.Combine(List.Transform(_, Text.From),", ")}})
in
    ShowList

PQ example.xlsx
ABCD
1StartEnd
21/1/20225/21/2022
32/3/20213/4/2022
43/5/20223/23/2022
5
6StartEndCustom
71/1/20225/21/20221/1/2022, 2/1/2022, 3/1/2022, 4/1/2022, 5/1/2022
82/3/20213/4/20222/1/2021, 3/1/2021, 4/1/2021, 5/1/2021, 6/1/2021, 7/1/2021, 8/1/2021, 9/1/2021, 10/1/2021, 11/1/2021, 12/1/2021, 1/1/2022, 2/1/2022, 3/1/2022
93/5/20223/23/20223/1/2022
10
Sheet4
Thanks,

Richard.
 
Upvote 0

Forum statistics

Threads
1,215,083
Messages
6,123,020
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top