• 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
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • 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
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Sum Multiple Columns by Matching Rows in First Column|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Sum Multiple Columns by Matching Rows in First Column|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
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 ForumPower QuerySum Multiple Columns by Matching Ro…
sp_PrintTopic sp_TopicIcon
Sum Multiple Columns by Matching Rows in First Column
Avatar
Adam Smith
Member
Members
Level 0
Forum Posts: 45
Member Since:
December 18, 2018
sp_UserOfflineSmall Offline
1
June 8, 2020 - 12:52 am
sp_Permalink sp_Print sp_EditHistory

Hello,

I'm working on an API connection for COVID tracking.

In Column 1 [Country_EN], I have many values:

Ireland

United Kingdom

United Kingdom

United Kingdom

United Kingdom

United Kingdom

United Kingdom

United Kingdom

etc.

 

The reason there are many United Kingdoms, is each row represents a region. Column 2 is [1/1/2020], column 3 is [2/1/2020] and so on. I need to keep all the columns as is, however, I need to group all the United Kingdoms in [Country_EN] and sum those values in the following columns. Essentially I'll be left with only two rows -

Ireland

United Kingdom

Any help is greatly appreciated! Thanks

sp_AnswersTopicSeeAnswer See Answer
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1512
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
June 8, 2020 - 8:45 am
sp_Permalink sp_Print sp_EditHistory

Hi Adam,

Without actually seeing your data I can't give the best answer.  You could perhaps use Power Query though that maybe overkill.  You could use SUMIFS or a PivotTable. 

Please supply the workbook, or at least a sample with the identical data structure (columns,rows).

Regards

Phil

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4443
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
3
June 8, 2020 - 9:21 am
sp_Permalink sp_Print

Hi Adam,

You can use the Group By tool in Power Query to group the data based on the Country column.

However, you said you have the dates going across the columns...depending on how you plan to analyse and summarise this data, I recommend you also use Power Query to unpivot it so you have a date in one column and the value in another. Then you can use PivotTables and SUMIFS formulas the way they were intended. i.e. working with tabular data.

Mynda

Avatar
Adam Smith
Member
Members
Level 0
Forum Posts: 45
Member Since:
December 18, 2018
sp_UserOfflineSmall Offline
4
June 8, 2020 - 9:49 pm
sp_Permalink sp_Print

Thank you both for responding. I'm really hoping I can keep the file light and handle most (if not all) of the work in Power Query, but I'll trust your judgments. I've attached the file, if you wouldn't mind taking a peek. I've also noticed, at least on my end, when I refreshed this morning it did not pull in all the current data. The CSV online says the most recent date is June 7, yet the file only updates to June 6. Could there be some sort of caching issue on my end?

Thanks again for your time!

Avatar
Adam Smith
Member
Members
Level 0
Forum Posts: 45
Member Since:
December 18, 2018
sp_UserOfflineSmall Offline
5
June 9, 2020 - 1:30 am
sp_Permalink sp_Print

With regards to the column count issue, it seems a limit of 140 was hard-coded into the Source step. I've learned that removing that section fixes the problem (Columns=140). If you've got any thoughts on preventing that in the future it'd be appreciate, too. Thanks again!

Avatar
Adam Smith
Member
Members
Level 0
Forum Posts: 45
Member Since:
December 18, 2018
sp_UserOfflineSmall Offline
6
June 9, 2020 - 3:17 am
sp_Permalink sp_Print

I'm pretty sure I was able to solve the problem by taking the source data, and pivoting it so all the dates were in one column and all the regions in the other, then pivoting it back, essentially, which I think should have combined the duplicates. Unless I'm mistaken

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1512
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
7
June 9, 2020 - 8:57 am
sp_Permalink sp_Print

Hi Adam,

Please see attached and compare to your solution.

After unpivoting the date columns, I've grouped by Country and Date to give the final table.

I've removed the Columns=140 too.

Regards

Phil

sp_AnswersTopicAnswer
Answers Post
Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4443
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
8
June 9, 2020 - 9:02 am
sp_Permalink sp_Print sp_EditHistory

Hi Adam,

There is no way to prevent the 'Columns=n' clause being automatically entered in the query. You just have to remember it's there and if you're expecting more columns in future, then remove it manually from the M code.

I agree with Phil's solution. You should not be pivoting the data again in Power Query. This is a job for the PivotTable or your later analysis. If you have your data already pivoted then it will be difficult to use Excel's built in tools and functions like SUMIF/S, COUNTIF/S and PivotTables and Slicers etc.

You should always start with tabular data. That's what Power Query is designed to output.

Hope that points you in the right direction.

Mynda

Avatar
Adam Smith
Member
Members
Level 0
Forum Posts: 45
Member Since:
December 18, 2018
sp_UserOfflineSmall Offline
9
June 9, 2020 - 9:27 pm
sp_Permalink sp_Print

Thank you both Mynda and Philip - you're rockstars. Philip your data matched what I was able to come up with and I couldn't be happier. Also, Mynda, your tabular data page is great. I'm going to share it with my boss for future reference to help us align in our goals.

 

Thanks again, very much.

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1512
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
10
June 10, 2020 - 9:09 am
sp_Permalink sp_Print

no worries 🙂

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Brian Pham
Guest(s) 8
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
drsven
Annie Witbrod
wahab tunde
Cong Le Duc
Faisal Bashir
Ivica Cvetkovski
Blaine Cox
Shankar Srinivasan
riyepa fdgf
Hannah Cave
Forum Stats:
Groups: 3
Forums: 24
Topics: 6205
Posts: 27211

 

Member Stats:
Guest Posters: 49
Members: 31880
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • 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
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

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.