• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Sum a column in VSTACK|General Excel Questions & Answers|Excel Forum|My Online Training Hub

You are here: Home / Sum a column in VSTACK|General Excel Questions & Answers|Excel Forum|My Online Training Hub

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumGeneral Excel Questions & Answe…Sum a column in VSTACK
sp_PrintTopic sp_TopicIcon
Sum a column in VSTACK
Avatar
Sam Aruti

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
January 13, 2023
sp_UserOfflineSmall Offline
1
January 13, 2023 - 6:46 am
sp_Permalink sp_Print

I have 2 tables, both have the same format, the data in each table is added by someone else. Each table has the same headings

Due Action Debit/Credit Balance where the Balance column is a calculation of Debit/Credit + previous Balance (=F??+[@[Debit/Credit]]).

To combine the tables I use the following function =SORT(VSTACK(Table1,Table2),1,1,FALSE). This works fine except that the Balance column is not a calculation with the new table but of each individual table. Is there any way to get the Balance to be the sum of the Debit/Credit of the combined table?

In advance, thanks for your help

sp_AnswersTopicSeeAnswer See Answer
Avatar
Riny van Eekelen
Örnsköldsvik, Sweden
Moderator
Members


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 384
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
2
January 13, 2023 - 5:30 pm
sp_Permalink sp_Print

Hi Sam,

As you have noticed, VSTACK (as does HSTACK) doesn't keep the formulas. It merely stacks the arrays as they are. You'd have to add a few extra steps. Since you have VSTACK, you have other DA functions at your disposal as well. The formula looks like this.

=LET(
stck, SORT(VSTACK(Table1,Table2),1,1,FALSE),
data, DROP(stck,,-1),
dc, TAKE(data,,-1),
rt, MMULT(--(SEQUENCE(COUNT(dc))>=SEQUENCE(,COUNT(dc))),dc),
result, HSTACK(data,rt),
result
)

In words, what this does is:

1) VSTACK both tables and SORT them (stck, that's your original formula)
2) DROP the last column (data)
3) TAKE the D/C column (dc)
4) Calculate the running total for D/C (rt)
5) HSTACK step 2 and 4 (result)

Step 4 is a subject by itself and you would need to study the MMULT function if you are not familiar with it.

The attached workbook contains a working example and I trust you are able to apply the same technique in your own. I'm open to hear about more effective ways to do this, as I can't think of any other solution just now.

sp_AnswersTopicAnswer
Answers Post
Avatar
Velouria
London or thereabouts
Member
Members


Trusted Members
Level 4
Forum Posts: 574
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
3
January 13, 2023 - 10:23 pm
sp_Permalink sp_Print

You could use SCAN for the running total:

rt, SCAN(0,dc,LAMBDA(a,b,a+b))

The following users say thank you to Velouria for this useful post:

Mynda Treacy
Avatar
Riny van Eekelen
Örnsköldsvik, Sweden
Moderator
Members


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 384
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
4
January 13, 2023 - 11:03 pm
sp_Permalink sp_Print

Good point! Thx.
@Velouria

Avatar
Sam Aruti

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
January 13, 2023
sp_UserOfflineSmall Offline
5
January 15, 2023 - 4:50 am
sp_Permalink sp_Print

Thank you both, the solution works perfectly. Now I have to understand what you did Laugh

Avatar
Riny van Eekelen
Örnsköldsvik, Sweden
Moderator
Members


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 384
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
6
January 16, 2023 - 6:37 pm
sp_Permalink sp_Print

The best way to analyze/understand a LET function is to see what every single step does. When you take my formula, replace the last word "return" with "stck" and press enter.

Now you see what the first step produces. That's your initial formula, stacking and sorting the two arrays.
Next, put "data" in as the last word (i.e. variable) of the formula. You'll see the stck-array with the last column removed.
Do that for the other variables as well, and see what each step does.

Avatar
Sam Aruti

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
January 13, 2023
sp_UserOfflineSmall Offline
7
January 17, 2023 - 8:37 pm
sp_Permalink sp_Print

Once again, thank you, great tip for someone learning LET

Avatar
Sam Aruti

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
January 13, 2023
sp_UserOfflineSmall Offline
8
January 17, 2023 - 8:40 pm
sp_Permalink sp_Print

@Velouria
Don't want to forget you in my appreciation, the SCAN is a lot easier to understand than MMULT as I still struggle with conceptualizing arrays

Avatar
Velouria
London or thereabouts
Member
Members


Trusted Members
Level 4
Forum Posts: 574
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
9
January 18, 2023 - 10:14 pm
sp_Permalink sp_Print

No worries - I confess my eyes tend to glaze over if I see MMULT in a formula. 😉

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 170
Currently Online: Brenda Krol, Peter Griffiths
Guest(s) 48
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1431
Anders Sehlstedt: 848
Velouria: 574
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 213
A.Maurizio: 202
Aye Mu: 201
Jessica Stewart: 185
Newest Members:
David Collins
Andras Marsi
Orimoloye Funsho
YUSUF IMAM KAGARA
PRADEEP PRADHAN
Vicky Otosnika
Abhishek Singh
Kevin Sojourner
Kara Weiss
And Woox
Forum Stats:
Groups: 3
Forums: 24
Topics: 6047
Posts: 26544

 

Member Stats:
Guest Posters: 49
Members: 31497
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Riny van Eekelen
© Simple:Press —sp_Information
  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
 
  • About My Online Training Hub
  • Contact
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Copyright © 2023 · My Online Training Hub · All Rights Reserved

Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.

Download A Free Copy of 100 Excel Tips & Tricks

excel tips and tricks ebook

We respect your privacy. We won’t spam you.

x