Advanced Formula Magic: Running total by row with dynamic arrays in Excel

Поделиться
HTML-код
  • Опубликовано: 24 янв 2025

Комментарии • 63

  • @Excelambda
    @Excelambda 3 месяца назад +11

    Great video !! Great solution !!
    For fun , we can change the order, in general, adding index rules and still use native GROUPBY and/or PIVOTBY results. (remove rules after if we want)
    Also for running totals good old MMULT can do the trick.
    step 1. extract inner array of the pivotby function; step 2: running tot MMULT(array, seq(4)

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +7

      WOW! 🤯 - that is some next level logic. Amazing!

    • @muhammadasad729
      @muhammadasad729 3 месяца назад +1

      Beautiful, simply genius. For anyone attempting to try and getting confused by ranges, use following formula with tabular ranges:
      =LET(p,PIVOTBY(Data[Item],XMATCH(Data[Region],UNIQUE(Data[Region]))&Data[Region],Data[Value],SUM,,0,,0),
      c,COUNTA(UNIQUE(Data[Region])),
      MMULT(DROP(IFERROR(--p,0),1,1),--(SEQUENCE(c)

    • @Excelambda
      @Excelambda 3 месяца назад +1

      @@muhammadasad729 Thank you!! 😊✌

  • @davescrams
    @davescrams 3 месяца назад +4

    Excellent demonstration of building up a solution and then refining the implementation for ease of understanding and reuse.

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +1

      Thank you. I'm glad it all made sense by the end.

  • @viktorasgolubevas
    @viktorasgolubevas 3 месяца назад +5

    Perfect! Generator MAKEARRAY is a very, very useful function...
    With dynamic arrays, we can simply SUM using (if/where) criteria, thus syntactically removing FILTER, eg
    =MAKEARRAY(COUNTA(F10#),COUNTA(G9#),
    LAMBDA(r,c,
    SUM( Data4[Value] * (r>=XMATCH(Data4[Item],F10#)) * (c=XMATCH(Data4[Region],G9#)) )
    ))
    And... I call this implementation "Running total by row" :) , ie column is fixed in the formula

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +2

      Ah, Yes! Very nice. Great stuff. Thanks for sharing. 👍

  • @kebincui
    @kebincui 3 месяца назад +3

    Brilliant and creative as always 👍. Thanks Mark for sharing your tips which are all gems ❤

  • @jenniferdustin8214
    @jenniferdustin8214 Месяц назад

    I'm a BIG fan of the Let function. I'd love to see a video on just that, and all the many ways it can be helpful. (and its faults too)

  • @IvanCortinas_ES
    @IvanCortinas_ES 3 месяца назад +1

    Excellent work, Mark. Absolutely logical in the process. Thank you very much for sharing these cases, as they respond to real situations in the company.

  • @chrism9037
    @chrism9037 3 месяца назад +2

    Excellent Mark!

  • @williamarthur4801
    @williamarthur4801 3 месяца назад +2

    Thanks, not used Makearray before, knew what it did just never really had a use.
    I did have a go at a dynamic version before watching , made the mistake of trying to put a let within Lambda, which mean it was trying to refer to something 'outside' , got there in the end.

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад

      I’m glad you got a solution. These new DA functions do take a bit of practice.

  • @johnhackwood1568
    @johnhackwood1568 Месяц назад

    Nice thanks Mark

  • @stanTrX
    @stanTrX 3 месяца назад +1

    This looks something super advanced and i dunno if i use it or not in my works but if i have to, thanks in advance for such solution

  • @GeertDelmulle
    @GeertDelmulle 3 месяца назад +4

    Great solution, Mark, for a tough problem. I think your solution is quite efficient.
    Yet, I respectfully disagree with the premise: those regional headers should not be used for cumulative sums because those results are misleading for the consumer of the report.
    But of course, this was only an example to prove a point. Again, well done. 👍

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +3

      Agreed, it would be an odd request to have regions in the columns. North, South, East, West are just easy to demonstrate the concepts with. However, having a running total by a non-alphabetical category is certainly a real scenario.

  • @asheeshpahwa7508
    @asheeshpahwa7508 3 месяца назад +2

    Amazing Mark!! Loved your solution. I tried to get this done with nested reduce and Scan but i found Makearray very powerful. I had to use double reduce to iterate through Item and then region but it was fun. Keep bringing these vedios. Thanks a lot.
    =DROP(REDUCE("",UNIQUE(F6:F21),LAMBDA(x,y,VSTACK(x,
    LET(f,FILTER(G6:H21,F6:F21=y),
    r,DROP(REDUCE("",UNIQUE(G6:G21),LAMBDA(a,v,HSTACK(a,
    SUM(FILTER(TAKE(f,,-1),TAKE(f,,1)=v,0))))),,1),
    I,IFNA(r,""),SCAN(0,I,LAMBDA(x,y,x+y)))))),1)

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +2

      That’s a bit of a brain melting function. I wonder if it’s possible with a single DROP/REDUCE/LAMBDA/VSTACK. I haven’t tried, but logically, it should be.

  • @ankursharma6157
    @ankursharma6157 3 месяца назад

    Loved It 👌🏽
    Thank You!

  • @prasoft2999
    @prasoft2999 3 месяца назад

    As usual, very very informative video(s).Thank you, Sir🙏 you are my guiding star.

  • @jhonathanalexandergonzales6662
    @jhonathanalexandergonzales6662 3 месяца назад

    Awesome! Definitely I'm gonna try it!

  • @wakeenaushad2058
    @wakeenaushad2058 3 месяца назад +6

    Just a quick thought, we could use CHOOSECOLS and CHOOSEROWS with the r and c parameters of make array to get the row names and columns names to be used inside the filter criteria . Would shorten the syntax by quite a bit

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +2

      I like it. I need to test it, but I like it 👍

    • @murugankuppusamy9411
      @murugankuppusamy9411 3 месяца назад

      I need vedio by this technique​@@ExcelOffTheGrid

  • @craigbauman3486
    @craigbauman3486 3 месяца назад +2

    Dude, you have a beautiful mind.

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +2

      My mind is normally quite chaotic, but occasionally something bubbles to the surface that might make sense 🤣

    • @DingusBatus
      @DingusBatus 3 месяца назад

      I second that.❤️

  • @GiorgioBerardi
    @GiorgioBerardi 3 месяца назад

    Maybe not the easiest syntax, but explained brilliantly!

  • @Ozgur-wq3sq
    @Ozgur-wq3sq 3 месяца назад +1

    Brilliant and please share more content with filter() function magic.

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +1

      I've got 3 or 4 videos about FILTER on the channel - go check them out. 😁

    • @Ozgur-wq3sq
      @Ozgur-wq3sq 3 месяца назад

      @@ExcelOffTheGrid Filter magic is never enough :)

  • @uzairali5318
    @uzairali5318 2 месяца назад +1

    you are good.

  • @NestorCirhuza
    @NestorCirhuza 2 месяца назад +1

    Hello @Marc, can this formula works when rhe data set is in a range instead of a table?

  • @att6098
    @att6098 3 месяца назад +1

    Mark, thanks for sharing the excellent solution. I learnt a lot from you. I have couple of questions:
    a. During the videio, you put "

  • @RonDavidowicz
    @RonDavidowicz 3 месяца назад +1

    Another great video.
    Question on the lambda function: in this formula you define r & c in the first part of the lambda functions, and then reference the r & c later in the function, but how does lambda “know” that r is 3, and c is 4?

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +5

      When using MAKEARRAY, it loops through the rows and columns.
      r = 1, c = 1
      r = 1, c = 2
      r = 1, c = 3
      r = 1, c = 4
      r = 2, c = 1
      r = 2, c = 2
      r = 2, c = 3
      r = 2, c = 4
      etc...
      Therefore, any LAMBDA inside MAKEARRAY must have 2 variables to accept the row and column values coming from MAKEARRAY.
      If there are 3 rows and 4 columns, the LAMBDA calculates 12 times (4 x 3) and returns each value to display in the array.
      It's the same with BYROW, it passes across 1 row. Therefore, the LAMBDA inside BYROW must have 1 variable declared.

    • @RonDavidowicz
      @RonDavidowicz 3 месяца назад +1

      @@ExcelOffTheGrid thank you, that’s a great explanation.

  • @arpwable
    @arpwable 3 месяца назад +2

    This is a beautiful construction, and very well explained, but I'm struggling to see why it'd be worthwhile to do this rather than a pivot table that could do the same thing...

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +3

      The calculation engine of standard PivotTables is too limited. Therefore, it's not long before people resort to copying/pasting interim results out of the PivotTables and then using formulas on those interim results. Which just creates unnecessary manual actions.
      So I avoid standard PivotTables as much as humanly possible. Sorry, I'm not a fan.

  • @DingusBatus
    @DingusBatus 3 месяца назад +2

    The majority of people say there is no such thing as witchcraft.
    Watching this and I’m not so sure.🤨
    Some serious spell casting going on there.🤪😂
    It’s good magic though, and even if you say it’s not really magic, just really good science, it’s very interesting either way.
    ❤️❤️

  • @davidabuang
    @davidabuang 3 месяца назад

    Nice use of MAKEARRAY here. MMULT can also accomplish it in one go using the same logic...
    =MMULT(--(TOROW(MATCH(Data[Item],F11#,0))=SEQUENCE(ROWS(F11#))),(MATCH(Data[Region],G10#,0)

    • @davidabuang
      @davidabuang 3 месяца назад

      And if MMULT gives you too much grief, GROUPBY can also get the job done by broadcasting the values across for each applicable region:
      =GROUPBY(Data[Item],(MATCH(Data[Region],G10#,0)

  • @Al-Ahdal
    @Al-Ahdal 3 месяца назад +1

    Hello Mark, why you have written "

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +1

      If we want a running total it needs to sum the previous quarters too.
      For Q3:
      - if we use “=“, it only gives Q3
      - if we use “

    • @Al-Ahdal
      @Al-Ahdal 3 месяца назад

      @@ExcelOffTheGrid Thank you

  • @Azoun83
    @Azoun83 3 месяца назад +1

    pivotby?

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад +1

      I don't think PIVOTBY has access to values outside of it's own filter context. So we could get the totals for North, South, East and West individually, but I don't think we can get the running total, as that would require access to the data for the other categories.
      BTW - I would love to be proved wrong; as I couldn't think of a way to do it with PIVOTBY, but there may be one.

  • @DOHOLINO30
    @DOHOLINO30 3 месяца назад +2

    Pivotby?

    • @ExcelOffTheGrid
      @ExcelOffTheGrid  3 месяца назад

      I don't think PIVOTBY has access to values outside of it's own filter context. So we could get the totals for North, South, East and West individually, but I don't think we can get the running total, as that would require access to the data for the other categories.
      BTW - I would love to be proved wrong; as I couldn't think of a way to do it with PIVOTBY, but there may be one.

  • @GiovanniGirelli-w3z
    @GiovanniGirelli-w3z 3 месяца назад

    Just a quick question. Wouldn’t this be a better solution?
    =LET(rowNames,K5#,colNames,L4#,rowPos,MATCH(Data[Flavor],rowNames, 0),colPos,MATCH(Data[Week],colNames, 0),result,MAKEARRAY(ROWS(rowNames),COLUMNS(colNames),LAMBDA(r,c,INDEX(FILTER(Data[Qty. Sold],(rowPos=r)*(colPos=c),0),1))),result)

  • @saichandu5965
    @saichandu5965 3 месяца назад

    How come you are getting unique formula as is in table format it won't works for me 😮😮

  • @Agressive324
    @Agressive324 3 месяца назад

    Thats my luck to see this video ❤️