如何在 power query 中创建日历 table
How to create a calendar table in power query
最早日期为 2021 年 8 月 1 日凌晨 12 点,增量为 30 分钟,最大日期为 DateTime.LocalNow()?
预期输出
08/01/2021 12:00:00 AM
08/01/2021 12:30:00 AM
08/01/2021 01:00:00 AM
代码
Source = List.DateTimes(#datetime(2021, 08, 01, 00, 00, 0), Duration.Days(Duration.From(DateTime.Date(DateTime.LocalNow())-(#datetime(2021, 08, 01, 00, 00, 0)))), #duration(0, 0, 30, 0)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
但我认为这不是正确的方法。另外我还是收到这个错误
Expression.Error: We cannot apply operator - to types Date and DateTime.
Details:
Operator=-
Left=10/20/2021
Right=8/1/2021 12:00:00 AM
在功率查询中使用以下M代码。
这将给出 100 个日期。您可以将步长 100 更改为您需要的值。
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtQ1sNQ1MlAwNLIyMAAipdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Datetime = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Datetime", type datetime}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each DateTime.LocalNow()),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type datetime}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Datetime", "Starttime"}, {"Custom", "Endtime"}}),
#"Added Custom1" = Table.AddColumn(#"Renamed Columns", "Dates", each List.DateTimes([Starttime], 100, #duration(0, 0, 30, 0))),
#"Expanded Dates1" = Table.ExpandListColumn(#"Added Custom1", "Dates")
in
#"Expanded Dates1"
最早日期为 2021 年 8 月 1 日凌晨 12 点,增量为 30 分钟,最大日期为 DateTime.LocalNow()?
预期输出
08/01/2021 12:00:00 AM
08/01/2021 12:30:00 AM
08/01/2021 01:00:00 AM
代码
Source = List.DateTimes(#datetime(2021, 08, 01, 00, 00, 0), Duration.Days(Duration.From(DateTime.Date(DateTime.LocalNow())-(#datetime(2021, 08, 01, 00, 00, 0)))), #duration(0, 0, 30, 0)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
但我认为这不是正确的方法。另外我还是收到这个错误
Expression.Error: We cannot apply operator - to types Date and DateTime.
Details:
Operator=-
Left=10/20/2021
Right=8/1/2021 12:00:00 AM
在功率查询中使用以下M代码。 这将给出 100 个日期。您可以将步长 100 更改为您需要的值。
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtQ1sNQ1MlAwNLIyMAAipdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Datetime = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Datetime", type datetime}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each DateTime.LocalNow()),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type datetime}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Datetime", "Starttime"}, {"Custom", "Endtime"}}),
#"Added Custom1" = Table.AddColumn(#"Renamed Columns", "Dates", each List.DateTimes([Starttime], 100, #duration(0, 0, 30, 0))),
#"Expanded Dates1" = Table.ExpandListColumn(#"Added Custom1", "Dates")
in
#"Expanded Dates1"