+ Reply to Thread
Results 1 to 14 of 14

How to total all numbers for a date (Row) when there are several columns with same name

  1. #1
    Registered User
    Join Date
    07-10-2021
    Location
    GENEVA
    MS-Off Ver
    EXCEL FOR MAC MICROSOFT 365
    Posts
    80

    How to total all numbers for a date (Row) when there are several columns with same name

    Help! I have an extremely large and complex Excel spreadsheet with hundreds of columns and rows. The rows are dates, and the columns are item names.

    In very simple terms, the spreadsheet looks like this: (Note the problem- more than one column has the same name). Also, both the dates and product titles might change. For example Apples may become Pears, and Pears may become Apples. I want the formula's output to take this into account. In other words, if I rename "Pears" to "Apples" the answer will become 83 instead of 53

    Date Apples Pears Apples
    01.05.21 2 15 33
    10.07.21 3 30 50
    15.07.21 6 40 210

    Choose Date 11.07.21
    Choose Product Apples
    Total Sales 53

    I just want a formula to give me the answer 53 in the example above. Seems easy? Not for me, and I am really good with Excel..
    I have tried all kinds of combinations of Index, xMatch, xlookup, sum, sumif and sumifs, and so on, but I just can't make it work. I could potentially make it work using the "=IF" formula, but that would result in hundreds of nested "IF"s, which is probably more that I, and Excel, want to handle.

    This seems at first sight to be such an easy problem to solve, but I have spent hours and can't figure out an easy solution .

    Screenshot 2021-07-10 at 12.46.09.png
    Last edited by TRICKYT57; 07-10-2021 at 06:55 AM. Reason: Solved by a genius!

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,986

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    Like this:

    =SUMPRODUCT(($A$5:$A$7=H5)*($B$4:$D$4=H6)*$B$5:$D$7)
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,986

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    You're welcome.



    It would be very nice if you were to just click the Add Reputation button at the foot of any of the posts of members who helped you reach a solution.

    Finally, if that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

  4. #4
    Registered User
    Join Date
    07-10-2021
    Location
    GENEVA
    MS-Off Ver
    EXCEL FOR MAC MICROSOFT 365
    Posts
    80

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    Thank you so much Glenn for the speedy reply! It has solved my problem. I must admit I had never come across the =SUMPRODUCT function before. That's what I love about Excel, there's a function for everything!

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    Hi,

    We generally prefer a representative copy of your workbook in whch you have manually entered the results you expect and clearly explain your calculation.

    From your description you seem to be picking the latest date prior to (or perhaps equal to) your stated date of 11/7/2021. You need to be clear on this and why not the sum of all previous dates.

    Perhaps

    =SUMIFS(OFFSET(B1:D1,MATCH(A7,A1:A4)-1,0,1,3),$B$1:$D$1,A8)

    Where A1:D4 is your data
    A7: 11/7/2021
    A8: Apples

    But first you'll need to ensure your column A dates are true date numbers and not just strings of text that look to you like a date.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,986

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    It's very useful and versatile... but can also be a bit temperamental, for example when there is text present in a range where it expects a number...

  7. #7
    Registered User
    Join Date
    07-10-2021
    Location
    GENEVA
    MS-Off Ver
    EXCEL FOR MAC MICROSOFT 365
    Posts
    80

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    Thank you very much Richard. That is very useful. I have tried it (combining SUMIFS with OFFSET and MATCH and it works for me too, just like Glenn's answer above using SUMPRODUCT. I will practice with both answers, I think they will both work, except that I will need to modify something in Glenn's answer if my date does not match exactly one in the table. In your case a non-matched date takes the earliest prior date - which is what I really want.

    I agree it would have been easier for all if I had uploaded my spreadsheet instead of a photo. I now see the instructions how to do that are as follows: "Just before posting, scroll down to GO ADVANCED, click, and then scroll down to MANAGE ATTACHMENTS and click again. Now follow the instructions at the top of that screen."

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,986

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    <= date... I didn't see that first time round. I'd tend to avoid OFFSET, as it's volatile and recalculates every time anything changes. I'd use this instead:

    =SUMPRODUCT(($A$5:$A$7=INDEX($A$5:$A$7,MATCH(H5,$A$5:$A$7,1)))*($B$4:$D$4=H6)*$B$5:$D$7)
    Attached Files Attached Files

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    Quote Originally Posted by TRICKYT57 View Post
    Thank you very much Richard. That is very useful. I have tried it (combining SUMIFS with OFFSET and MATCH and it works for me too, just like Glenn's answer above using SUMPRODUCT. I will practice with both answers, I think they will both work, except that I will need to modify something in Glenn's answer if my date does not match exactly one in the table. In your case a non-matched date takes the earliest prior date - which is what I really want.
    Stating the obvious but it would be even easier if your data was collected in a regular and normalised 2 dimensional table. In your case columns for Date, Fruit, and Number. You could then avoid functions altogether and use a Pivot Table, or of course simplified functions.

    It happens a lot where a bad design for data collection means hoops have to be jumped through to then summarise or analyse data. Better to get the database correct in the first place. It's always easier to report from a structured data set than complicate stuff by not having one.

  10. #10
    Registered User
    Join Date
    07-10-2021
    Location
    GENEVA
    MS-Off Ver
    EXCEL FOR MAC MICROSOFT 365
    Posts
    80

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    Glenn and Richard,

    Thank you both. Glenn, I see how the use of Index and Match can be used to find the nearest earlier date. It’s just the solution I need.

    Richard, I am struggling to understand what you meant by better layout of my data. I love pivot tables and use them all the time. However I don’t get what you mean by putting everything in columns. I am all for a better layout to make things easier.

  11. #11
    Registered User
    Join Date
    07-10-2021
    Location
    GENEVA
    MS-Off Ver
    EXCEL FOR MAC MICROSOFT 365
    Posts
    80

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    Glenn, I spent some time figuring out why your formula =SUMPRODUCT(($A$5:$A$7=INDEX($A$5:$A$7,MATCH(H5,$A$5:$A$7,1)))*($B$4:$D$4=H6)*$B$5:$D$7) actually worked. I was convinced that the number 1 in the MATCH function you showed me should be a minus 1. I didn't notice that I was using XMATCH, and you suggested MATCH. I have always used the XMATCH function, which is described as a "robust and flexible successor to the MATCH function". Finally I discovered a weird anomaly between MATCH and XMATCH. The match_type argument is back-to-front between the two functions. 1 is -1 and -1 is 1! I guess you know this but it wasn't obvious to me!

    MATCH: match_type - [optional] 1 = exact or next smallest (default), 0 = exact match, -1 = exact or next largest.
    XMATCH: match_mode - [optional] 0 = exact match (default), -1 = exact match or next smallest, 1 = exact match or next larger, 2 = wildcard match.

    Who would have thought that Microsoft would have made an upgrade function with the arguments back-to-front from the previous one?

  12. #12
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    Quote Originally Posted by TRICKYT57 View Post
    Glenn and Richard,

    Thank you both. Glenn, I see how the use of Index and Match can be used to find the nearest earlier date. It’s just the solution I need.

    Richard, I am struggling to understand what you meant by better layout of my data. I love pivot tables and use them all the time. However I don’t get what you mean by putting everything in columns. I am all for a better layout to make things easier.
    Hi,

    The essence of a normalised database range is that each column should be a UNIQUE TYPE of thing. In a PT when you want to summarise information about a single fruit then you just need to include the fruit column in the field list. You can't easily compare or summarise stuff in a PT when you have several columns (fields) that represent the same item.

    Your layout has fruits as a type of thing, hence you should have a single column headed Fruits and record the type of fruit in that column. As a bonus typically you'll have less white space in a database.

  13. #13
    Registered User
    Join Date
    07-10-2021
    Location
    GENEVA
    MS-Off Ver
    EXCEL FOR MAC MICROSOFT 365
    Posts
    80

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    Thanks Richard, I get it. Each column should be a unique fruit. The fact is I over-simplified my problem. To build my consolidated table I am having to import data in the form of csv files. I am not in control of the source files. As an analogy, imagine that I have multiple salesmen selling fruit and vegetables. Each submits a csv file of how many apples he sold, along with all the other fruit and vegetables per day for the last year. There's nothing I can do to force a specific or even a consistent order. Each day the fruits are in a different order. Every salesman submits his sales in a different order from any other salesman.Your point is a good one. With a bit of luck I will find a solution to harmonise the data.

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: How to total all numbers for a date (Row) when there are several columns with same nam

    I've moved your new post to its own thread here: https://www.excelforum.com/excel-for...-same-nam.html

    Please go there and update the title to reflect the new request.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Calculating Total of Repeating Columns Due to Day/Date
    By rad1224 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-15-2020, 04:15 AM
  2. Compare numbers and add to total by date
    By bewise in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2013, 03:29 PM
  3. Replies: 5
    Last Post: 07-22-2013, 05:56 PM
  4. Sum multiple columns if total in another column is between 2 numbers
    By CLG107307 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-03-2013, 10:51 AM
  5. Sum total numbers for only a certain date
    By Craddock in forum Excel General
    Replies: 2
    Last Post: 06-15-2009, 10:17 AM
  6. Simple Total of Two Columns Containing Numbers and Words
    By SniperNinja in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-13-2007, 03:52 AM
  7. [SOLVED] 2 columns with duplicate names and total numbers
    By Ana in forum Excel General
    Replies: 3
    Last Post: 03-30-2006, 12:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1