+ Reply to Thread
Results 1 to 8 of 8

Sum Cells when Values Change in Two Other Columns

  1. #1
    Registered User
    Join Date
    03-02-2015
    Location
    Louisville, KY
    MS-Off Ver
    2008
    Posts
    8

    Sum Cells when Values Change in Two Other Columns

    So I have an employee mileage log and I would like my spreadsheet to be able to generate subtotals based on shift (shifts are denoted by a change in date and/or participant). I have come at this project from a number of different angles but keep hitting a wall. I did find a great formula in an article I found, but there are other factors that need to be incorporated into the formula and I'm not sure how to do that.


    =IF(A9<>A8,SUM($H$8:H8)-SUM($M$7:M7),"")


    Essentially, I need a formula that will sum all cells in my desired range that 1) are on the same day, 2) are associated with the same participant, and 3) are not part of the employee's commute.

    Ideally, I'd like these subtotals to generate as employees add data to the spreadsheet, rather than someone needing to use the built-in filter feature or built-in subtotal feature after the fact. Anyone have any ideas?

    A = Date
    B= Participant (generated from a drop-down)
    G= Includes commute? (generated from a drop-down Y/N)
    H= Miles Traveled (the values I want to sum)
    Attached Images Attached Images

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,447

    Re: Sum Cells when Values Change in Two Other Columns

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Registered User
    Join Date
    03-02-2015
    Location
    Louisville, KY
    MS-Off Ver
    2008
    Posts
    8

    Re: Sum Cells when Values Change in Two Other Columns

    Thank you for the suggestions.

    I have attached a spreadsheet with some dummy data. Essentially, I'm hoping to find a formula that will calculate subtotals for each "shift." Then, I would like all shift totals greater than 20 miles to be subtracted from the mileage total(L4)only when the overages have not been approved (column P). If there were a way to generate totals in column M any time the date and participant changed in columns A and C (excluding commutes), that would be ideal. I was able to generate shift totals based on that criteria in the Shift Totals tab, but I haven't been able to find a way to extract the pertinent data and arrange it in the way I need to on the Mileage tab so I'm hoping there's a formula I can use in column M that will streamline the process. Any suggestions?
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-02-2015
    Location
    Louisville, KY
    MS-Off Ver
    2008
    Posts
    8

    Re: Sum Cells when Values Change in Two Other Columns

    This is what I imagine it would like like but my logic or syntax must be off.

    =IF((AND(A9<>A8,C9<>C8,A8="N")),SUM($H$8:H8)-SUM($M$7:M7),"")
    Last edited by rnbblsmm; 09-18-2019 at 02:39 PM.

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,726

    Re: Sum Cells when Values Change in Two Other Columns

    You can use this in M8:

    =IF(OR(A9<>A8,C9<>C8),SUMIFS($H$8:H8,$A$8:A8,A8,$C$8:C8,C8)-COUNTIFS($A$8:A8,A8,$C$8:C8,C8,$G$8:G8,"Y")*$L$3,"")

    then copy down. I've taken the view that as you have a commute distance in L3, then if the distance is 27 and this includes the commute, then 7 miles should be added on to the figures that you show, so the numbers differ from yours. This is easy to change if you only want to add the mileage where Include Commute is N.

    Hope this helps.

    Pete

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,726

    Re: Sum Cells when Values Change in Two Other Columns

    This is the formula to use in M8 if you want the numbers to be the same as yours:

    =IF(OR(A9<>A8,C9<>C8),SUMIFS($H$8:H8,$A$8:A8,A8,$C$8:C8,C8,$G$8:G8,"N"),"")

    Copy down as required.

    Hope this helps.

    Pete

  7. #7
    Registered User
    Join Date
    03-02-2015
    Location
    Louisville, KY
    MS-Off Ver
    2008
    Posts
    8

    Re: Sum Cells when Values Change in Two Other Columns

    Thank you, Pete! That does the trick! I appreciate your help!

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,726

    Re: Sum Cells when Values Change in Two Other Columns

    You're welcome.

    If that takes care of your original question, please take a moment to select Thread Tools from the menu above and to the right of your first post in this thread, and mark the thread as SOLVED.

    Also, you might like to know that you can directly thank those who have helped you by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).

    Pete

+ 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. Using Values in VBA that change when inserting Rows/Columns
    By NewYears1978 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-07-2018, 03:39 PM
  2. [SOLVED] Matching values in two columns, then comparing values in adjacent cells
    By crfcaio in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-03-2017, 07:40 PM
  3. [SOLVED] Change a cells Text based on the Values of 3 other cells
    By cityinbetween in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-08-2014, 06:58 PM
  4. Replies: 8
    Last Post: 03-16-2011, 02:16 PM
  5. Validation list to change columns values
    By avisamo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-26-2009, 06:27 AM
  6. Inserting sub-total after change in values in three columns
    By vjboaz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-16-2008, 10:40 AM
  7. Formula needed for % change for 2 columns values
    By FredricJLowe in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-11-2006, 11:07 AM

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