다음을 통해 공유


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)
}