才分不够,只能用笨方法。
这个问题,实在太为难PQ了。
- let
- xSource = 表1,
- xRows = Table.RowCount(xSource),
- xColumnNames = Table.ColumnNames(xSource),
- xCols = List.Count(xColumnNames),
- fx取代全表 = (tbl, xOld, xNew) => Table.ReplaceValue(tbl,xOld,xNew,Replacer.ReplaceValue, Table.ColumnNames(tbl)),
- fxR读取值=(tbl as table, x坐标 as number, y坐标 as number) =>
- if x坐标<1 or y坐标<1 then
- 0
- else
- Record.Field(tbl{y坐标-1},Table.ColumnNames(tbl){x坐标-1}),
- fxW修改值=(tbl as table, x轴 as number, y轴 as number, newValue as any)=>
- let
- xColumns = Table.ColumnNames(tbl),
- x轴N=xColumns{x轴-1},
- xIndex = Table.AddIndexColumn(tbl, "Index", 1, 1, Int64.Type),
- xTemp = Table.AddColumn(xIndex, "temp", each if [Index]=y轴 then newValue else Record.Field(_,x轴N)),
- xRemove = Table.RemoveColumns(xTemp,{x轴N, "Index"}),
- xRename = Table.RenameColumns(xRemove,{{"temp", x轴N}}),
- xReOrder = Table.ReorderColumns(xRename,xColumns)
- in
- xReOrder,
- x_1 = List.Accumulate({1..xCols}, xSource, (accX,x)=>
- List.Accumulate({1..xRows}, accX, (accY,y)=>
- let
- x值 = fxR读取值(accY,x,y),
- x上 = fxR读取值(accY,x,y-1),
- x下 = if y+1>xRows then 0 else fxR读取值(accY,x,y+1),
- x左 = fxR读取值(accY,x-1,y),
- x右 = if x+1>xCols then 0 else fxR读取值(accY,x+1,y),
- xList = {x值,x上,x下,x左,x右},
- xMaxList = List.Max(xList),
- xMaxTbl = List.Accumulate(Table.ToRows(accY),0,(accZ,z)=> if List.Max(z)>accZ then List.Max(z) else accZ),
- xValue = if xMaxTbl = 1 then 2 else if xMaxList=1 then xMaxTbl+1 else xMaxList,
- x值1 = if x值=0 then accY else fxW修改值(accY,x,y,xValue),
- x上1 = if x值=0 or x上=0 then x值1 else if x上=1 then fxW修改值(x值1,x,y-1,xValue) else fx取代全表(x值1,x上,xValue),
- x下1 = if x值=0 or x下=0 then x上1 else if x下=1 then fxW修改值(x上1,x,y+1,xValue) else fx取代全表(x上1,x下,xValue),
- x左1 = if x值=0 or x左=0 then x下1 else if x左=1 then fxW修改值(x下1,x-1,y,xValue) else fx取代全表(x下1,x左,xValue),
- x右1 = if x值=0 or x右=0 then x左1 else if x右=1 then fxW修改值(x左1,x+1,y,xValue) else fx取代全表(x左1,x右,xValue)
- in
- x右1
- )),
- Result = List.Count(List.Distinct(List.Accumulate(Table.ToRows(x_1),{},(acc,x)=>acc&x)))-1
- in
- Result
复制代码 |