Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

350
Visualizações
Is it possible to step through a row of data and sum every n-th cell using a Lambda function?

I have a model that produces an array of values that can be several hundred columns wide. Every 25th column contains a number that I need to add to the total.

I thought the cleanest solution would be creating a LAMBDA function that would take the starting cell from the user's input and then offset across the row 25 cells, add the value there to a running total, and continue the offset stepping until it reached an empty cell.

Is it possible? How to do it?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

I don't think it's possible to loop as you wish in Excel with normal functions (you can do it with VBA tough). But you may benefit from DESREF and SUMPRODUCT to sum up values every n-th columns.

As example I made a fake dataset:

enter image description here

Got values from columns 1 to 30 (A to AD). I want to sum up values every 5 columns (1, 5, 10, 15,... and so on). The borded cells are the manual calculated results to understand logic but you can do it in a single formula:

=SUMPRODUCT(--(COLUMN(OFFSET(A4;0;0;1;COUNTA(A4:AD4)+COUNTBLANK(A4:AD4)))/5=INT(COLUMN(OFFSET(A4;0;0;1;COUNTA(A4:AD4)+COUNTBLANK(A4:AD4)))/5))*A4:AD4)+A4

This is how it works:

  1. COUNTA(A4:AD4)+COUNTBLANK(A4:AD4) this will return how many columns, including blanks, got your data
  2. OFFSET will create a range from first to nth column (result from previous step)
  3. SUMPRODUCT will sum up every nth value that row (in my example, every 5 columns)
  4. We manually add the first input, column 1, at the end of the formula

If you want every 25 columns, just replace the /5 with /25

over 4 years ago · Santiago Trujillo Relatório

0

You should be able to do this with a recursive LAMBDA.

StridingSum = LAMBDA(cell, step, [start],
    LET(
        colOffset, IF(ISOMITTED(start), -1, start) + step,
        value, OFFSET(cell, 0, colOffset),
        IF(
            value = "", 
            0,
            value + StridingSum(cell, step, colOffset)
        )
    )
);

Which you call as =StridingSum(A2, 25) (assuming your data started in A1)

over 4 years ago · Santiago Trujillo Relatório

0

This might work slightly better than Paul's in allowing you to select the first cell of data rather than the second.

StridingSum = LAMBDA(cell, step, [start],
LET(
    colOffset, IF(ISOMITTED(start), 0, start + step),
    value, OFFSET(cell, 0, colOffset),
    IF(
        value = "", 
        0,
        value + StridingSum(cell, step, colOffset)
    )
)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda