|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我试了一下,Table.TranformColumns一一用函数说有问题,执行不了
但是直接输入一个Table进去可以,实在是见鬼了,用的循环输入18个Table进去的。
看你的要求是:
1. 是达到目标的。
2.要持续三个月增长的。
- let
- fn = (lst,n) =>
- let
- 服装 = Table.AddIndexColumn(Table.AddColumn(lst,"达到目标",each if [销售额]>[销售目标] then 1 else -1),"Index"),
- result = Table.Last(Table.SelectRows(
- Table.AddColumn(Table.Group(
- Table.TransformColumns(服装, {"Index",each if _=0 then -1 else Number.Sign(服装[销售额]{_}-服装[销售额]{_-1})+服装[达到目标]{_}}),
- {"Index"},{{"Count",each _[日期]}},0),"数量",each List.Count([Count])),each ([Index]=2 and [数量]>=n)))[Count]
- in result,
- Source = Table.Group(Excel.CurrentWorkbook(){[Name="Table1"]}[Content], {"类别", "产品"}, {{"Count", each _}}),
- Source1 = Table.TransformColumns(Source,{"Count",each Table.AddIndexColumn(Table.AddColumn(Source[Count]{0},"达到目标",each if [销售额]>[销售目标] then 1 else -1),"Index")}),
- D = List.Transform({0..17},each fn(Source[Count]{_},2)),
- B = Table.TransformColumns(Table.AddIndexColumn(Source1,"Result"),{"Result",each Record.FromList({List.Count(D{_}),List.First(D{_}),List.Last(D{_})},{"Month","Start","End"})}),
- C = Table.ExpandRecordColumn(B, "Result", {"Month", "Start", "End"}, {"Month", "Start", "End"}),
- Result = Table.TransformColumnTypes(C,{{"Start", type date}, {"End", type date}})
- in
- Result
复制代码 |
|