次の方法で共有


List.Accumulate

構文

List.Accumulate(
    list as list,
    seed as any,
    accumulator as function
) as any

バージョン情報

アキュムレータを使用して、指定したリスト内の項目の集計値を累積します。

  • list: 反復処理するリスト。
  • seed: 最初の累積値。
  • accumulator: 現在の状態と現在の項目を受け取り、新しい状態を返す関数。

例 1

リスト内のアイテムの集計値を累積します。

使用方法

let
    Source = List.Accumulate(
        {1, 2, 3, 4, 5},
        0,
        (runningSum, nextNumber) => runningSum + nextNumber
    )
in
    Source

アウトプット

15

例 2

リスト内の各単語をスペースで連結しますが、先頭にスペースを含めないでください。

使用方法

let
    Source = List.Accumulate(
        {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog."},
        null,
        (fullTextSoFar, nextPart) =>
            Text.Combine({fullTextSoFar, nextPart}, " ")
    )
in
    Source

アウトプット"The quick brown fox jumps over the lazy dog."

例 3

開始日からプロセスの完了時間の一覧とプロセスの実行時間の一覧を作成します。

使用方法

let
    #"Process Duration" = 
    {
        #duration(0,1,0,0),
        #duration(0,2,0,0),
        #duration(0,3,0,0)
    },
    #"Start Time" = #datetime(2025, 9, 8, 19, 0, 0),
    #"Process Timeline" = List.Accumulate(
        #"Process Duration",
        {#"Start Time"},
        (accumulatedTimes, nextDuration) => 
            accumulatedTimes & {List.Last(accumulatedTimes) + nextDuration}
    )
in
    #"Process Timeline"

アウトプット

{
    #datetime(2025, 9, 8, 19, 0, 0),
    #datetime(2025, 9, 8, 20, 0, 0),
    #datetime(2025, 9, 8, 22, 0, 0),
    #datetime(2025, 9, 9, 1, 0, 0)
}