PQ 方案,香不香???????????
- <div class="blockcode"><blockquote>let
- 源 = Excel.CurrentWorkbook(){[Name = "表1"]}[Content],
- Tab1 = Table.RemoveColumns(源, {"列1", "列2", "列3"}),
- Tab2 = Table.TransformColumnTypes(
- Tab1,
- {
- {"价格", type text},
- {"代码", type text},
- {"商品", type text},
- {"入库", type text},
- {"出库", type text},
- {"余额", type text},
- {"比例", type text}
- }
- ),
- Tab3 = Table.ReplaceErrorValues(
- Tab2,
- {
- {"价格", null},
- {"代码", null},
- {"商品", null},
- {"入库", null},
- {"出库", null},
- {"余额", null},
- {"比例", null}
- }
- ),
- Tab4 = Table.RemoveColumns(Tab3, {"余额"}),
- Tab5 = Table.TransformColumns(
- Tab4,
- {
- {
- "价格",
- each List.Transform(
- Splitter.SplitTextByRepeatedLengths(7)(_),
- each
- if Text.Contains(_, ".") then
- Text.PadEnd(_, 7, "0")
- else
- Text.PadEnd(_ & ".", 7, "0")
- )
- },
- {"代码", each Splitter.SplitTextByRepeatedLengths(6)(_)},
- {
- "入库",
- each [
- a = Text.BeforeDelimiter(_, "万"),
- b =
- if Text.Contains(a, ".") then
- {Text.PadEnd(a, 6, "0")}
- else
- List.Transform(
- Splitter.SplitTextByRepeatedLengths(6)(a),
- each Text.From(Number.Round(Number.From(_) / 10000, 2))
- )
- ][b]
- },
- {
- "出库",
- each [
- a = Text.BeforeDelimiter(_, "万"),
- b =
- if Text.Contains(a, ".") then
- {Text.PadEnd(a, 6, "0")}
- else
- List.Transform(
- Splitter.SplitTextByRepeatedLengths(6)(a),
- each Text.From(Number.Round(Number.From(_) / 10000, 2))
- )
- ][b]
- },
- {
- "比例",
- each [
- a = Splitter.SplitTextByCharacterTransition({"0" .. "9"}, {"-"})(_),
- b = List.Transform(a, each Text.PositionOf(_, ".", 2)),
- c = List.Transform(b, each {0} & List.Transform(_, (x) => x + 3)),
- d = List.Select(
- List.Combine(
- List.Accumulate(
- {0 .. List.Count(b)},
- {},
- (x, y) => x & {try Splitter.SplitTextByPositions(c{y})(a{y}) otherwise {null}}
- )
- ),
- each _ <> null and _ <> ""
- )
- ][d]
- }
- }
- ),
- Lst1 = Table.ToColumns(Tab5),
- Lst2 = List.Transform(Lst1, each if _{0} is text or _{0} = null then _ else List.Combine(_)),
- Lst3 = Lst2,
- Lst4 = List.Transform(List.Zip({Lst3{3}, Lst3{4}}), each Number.From(_{0}) - Number.From(_{1})),
- Lst5 = List.InsertRange(Lst3, 5, {Lst4}),
- Cols = Table.ColumnNames(Tab1),
- Result = Table.FromColumns(Lst5, Cols)
- in
- Result
复制代码
|