请问如何把日期范围展开(按每一天),并计算平均?
转换前:
StartDate | EndDate | Qty |
---|---|---|
2020-07-01 | 2020-07-02 | 3 |
转换后:
Date | Average |
---|---|
2020-07-01 | 1.5 |
2020-07-02 | 1.5 |
请问如何把日期范围展开(按每一天),并计算平均?
转换前:
StartDate | EndDate | Qty |
---|---|---|
2020-07-01 | 2020-07-02 | 3 |
转换后:
Date | Average |
---|---|
2020-07-01 | 1.5 |
2020-07-02 | 1.5 |
以下代码仅供参考
let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
转换 = Table.AddColumn(源
,"天数"
,each
[
日期=List.Transform(
{Number.From([StartDate])..Number.From([EndDate])}
,(x)=>Date.From(x)
)
,Qty1=[Qty]/(Number.From([EndDate]-[StartDate])+1)
]
),
展开 = Table.ExpandRecordColumn(转换, "天数", {"日期", "Qty1"}),
展开2 = Table.ExpandListColumn(展开, "日期")
in
展开2