编号T13会随机排列在表格中,需要一列来统计这次T13出现与上次出现的间隔数,如图所示第二个T13与第一个T13间隔数是7,第三个T13与第二个T13间隔数是13
编号T13会随机排列在表格中,需要一列来统计这次T13出现与上次出现的间隔数,如图所示第二个T13与第一个T13间隔数是7,第三个T13与第二个T13间隔数是13
参考
let
源 = Excel.CurrentWorkbook(){[Name="demo"]}[Content],
索引 = Table.AddIndexColumn(源, "结果", 0, 1),
sxb=Table.Buffer(Table.SelectRows(索引,(t)=> t[条件] = "T13")),
result = Table.ReplaceValue(索引,each _,null,(X,Y,Z)=>
if Y[条件]="T13" then
let
tb=Table.SelectRows(sxb, (sx)=> sx[结果] <= Y[结果] ),
l=Table.LastN(tb,2)[结果]
in
if List.Count(l)=1 then 0 else l{1}- l{0}
else null
,{"结果"}),
类型 = Table.TransformColumnTypes(result,{{"编号", type text}, {"日期", type date}, {"时间", type time}, {"条件", type text}, {"结果", Int64.Type}})
in
类型
参考
let
源 = Excel.CurrentWorkbook(){[Name="demo"]}[Content],
索引 = Table.AddIndexColumn(源, "结果", 0, 1),
sxb=Table.Buffer(Table.SelectRows(索引,(t)=> t[条件] = "T13")),
result = Table.ReplaceValue(索引,each _,null,(X,Y,Z)=>
if Y[条件]="T13" then
let
tb=Table.SelectRows(sxb, (sx)=> sx[结果] <= Y[结果] ),
l=Table.LastN(tb,2)[结果]
in
if List.Count(l)=1 then 0 else l{1}- l{0}
else null
,{"结果"}),
类型 = Table.TransformColumnTypes(result,{{"编号", type text}, {"日期", type date}, {"时间", type time}, {"条件", type text}, {"结果", Int64.Type}})
in
类型
fyi...
= let a = Table.PositionOf(源,[条件="T13"],2,each [条件]),
b = List.Zip({a,{null}&a}),
c = List.TransformMany( b,
each if _{0}=null then {} else
if _{1}=null then List.Repeat({null},_{0})&{0} else
List.Repeat({null},_{0}-_{1}-1)&{_{0}-_{1}},
(x,y)=>y )
in Table.FromColumns( Table.ToColumns(源)&{c}, Table.ColumnNames(源)&{"结果"} )
let
源 = Excel.CurrentWorkbook(){[Name="demo"]}[Content],
acc = List.Accumulate( Table.ToRecords(源),
{{},"",0},
(s,c)=>if c[条件]="T13" then
if s{1}="T13" then
{s{0}&{c&[结果=s{2}]},c[条件],1}
else {s{0}&{c&[结果=null]},c[条件],1}
else {s{0}&{c&[结果=null]},s{1},s{2}+1} ),
rlt = Table.FromRecords(acc{0})
in
rlt
顺便问下,源文件从哪下载?没找到,就自己随便模拟了一个