+ Reply to Thread
Results 1 to 22 of 22

Unable to get COUNTIF Formula to Calculate two columns

  1. #1
    Registered User
    Join Date
    04-14-2023
    Location
    United States
    MS-Off Ver
    Office 365
    Posts
    13

    Cool Unable to get COUNTIF Formula to Calculate two columns

    Good Afternoon!!!!

    I am working on a vehicle inventory tracker I am hoping all can help me with. I am have attached a copy of the file for your reference. I am trying to calculate the inventory that each district / site has on has on hand. I am trying to get the COUNTIF formula to use two criteria's BUT I do not want it to calculate the SUM for each criteria and double my numbers. The formula I tried to use is =COUNTIF(A3:A10,"1/1")-COUNTIF(D3:D10,"Chevrolet"). I am trying to get the formula to calculate the number of vehicle brands based on each site. In the formula above I reference "1/1" and that is the District / Site and my second reference is the make of the vehicle. I used the minus symbol between the COUTIF because I did not want it to double the quantity. I hope this all makes sense. Please reference the attachments and please ask any questions for clarification.

    Screenshot 2023-04-24 123630.png

    Vehicle Inventory.xlsx

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Chevrolet has a space at the end in column D

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Are you looking for the COUNTIFS() function? =COUNTIFS(A3:A10,"1/1",D3:D10,"Chevrolet")

    COUNTIFS() help file: https://support.microsoft.com/en-us/...rs=en-us&ad=us
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    copied across and down.

    Note that Chevrolet has trailing spaces.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    04-14-2023
    Location
    United States
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Thanks for catching the trailing spaces!!! I tried the formula you sent TMS and I couldn't get it to work. Maybe I am doing something wrong??

    Here is an example formula that I am currently using on a much larger tracker. =COUNTIF(E10:E275,"Text 1")+COUNTIF(E10:E275,"Text 2") . Now this formula is calculating the sum for each time Text 1 & Text 2 is listed in the same column and displays the combined quantity at the bottom of my tracker. What I am trying to do is the similar except across two different columns instead of just 1. Maybe that where the COUNTIFS() comes in that MrShorty mentioned above? I want the formula to reference the "District / Site" and calculate all the "Makes" at each site and display the quantity at the bottom next to their Site #.

    Here is a clip of the formula TMS gave me.


    Screenshot 2023-04-24 135917.png



    This is what I am trying to get the formula to do. Obviously I inputted the data manually and I did not use a formula.

    Screenshot 2023-04-24 140957.png

  6. #6
    Forum Expert
    Join Date
    09-25-2015
    Location
    Milan Italy
    MS-Off Ver
    office 365
    Posts
    1,783

    Re: Unable to get COUNTIF Formula to Calculate two columns

    B14=IF(AND(B$13<>"",$A14<>""),SUMPRODUCT((SUBSTITUTE($A$3:$A$10,"1/","")=TRIM(SUBSTITUTE($A14,"Site","")))*($D$3:$D$10=B$13)),"")

    Copy across and down

  7. #7
    Forum Expert wk9128's Avatar
    Join Date
    08-15-2020
    Location
    Australia
    MS-Off Ver
    365 V2403 and WPS V2022
    Posts
    3,439

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Cell B14 formula , Drag down and across
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-14-2023
    Location
    United States
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Please take a look at the attached spreadsheet. I tried to copy the formulas into the cells and this is all I am getting. I might be misunderstanding or doing something wrong. I appreciate all the help!!!


    Vehicle Inventory 2.xlsx

  9. #9
    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,955

    Re: Unable to get COUNTIF Formula to Calculate two columns

    In B14 you need this:

    =IF(AND(B$13<>"",$A14<>""),SUMPRODUCT((SUBSTITUTE($A$3:$A$10,"1/","")=TRIM(SUBSTITUTE($A14,"Site","")))*($D$3:$D$10=B$13)),"")

    Then copy across and down.
    Attached Files Attached Files
    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.

  10. #10
    Registered User
    Join Date
    04-14-2023
    Location
    United States
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Thank you for the help AliGW. This formula worked perfectly.

    I have another question I am hoping someone will be able to help with. I am going to break down how I am understanding a portion of this formula thus will lead to my next question.

    Formula:

    =IF(AND(B$13<>"",$A14<>""),SUMPRODUCT((SUBSTITUTE($A$3:$A$10,"1/","")=TRIM(SUBSTITUTE($A14,"Site","")))*($D$3:$D$10=B$13)),"")

    The portions of the formula =TRIM(SUBSTITUTE($A14,"Site","") is essential taking out "Site" from the cell and leaving the Site number and in this case its reading it as 1 instead of Site 1. Please correct me if I am wrong.

    My next question is how can I had a second =Trim like above? My assumption would like this below. Again correct me if I am wrong.

    =IF(AND(C$13<>"",$A14<>""),SUMPRODUCT((SUBSTITUTE($A$3:$A$10,"1/","")=TRIM(SUBSTITUTE($A14,"Site","")=TRIM(SUBSTITUTE($C13,"MY TEXT","")))*($E$3:$E$10=C$13)),"")

    In my master tracker I have another substitution I need input in column E instead of D and the example above is how I was thinking it would be implemented however, I am receiving #VALUE! in the cell instead of the number. The "MY TEXT" is what I am trying to substitute so the formula will only count FRP instead of "MY TEXT FRP". I hope this was descriptive enough. Please let me know if there any questions.

  11. #11
    Registered User
    Join Date
    04-14-2023
    Location
    United States
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Unable to get COUNTIF Formula to Calculate two columns

    I adjusted my example spreadsheet from the previous posts so maybe everyone can see what I am trying to do. You will see my issue in Column F. I think if this can be resolved I should be set. Thanks for all the help.

    Vehicle Inventory 3.xlsx
    Attached Files Attached Files

  12. #12
    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,955

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Try this:

    =IF(AND(E$13<>"",$A14<>""),SUMPRODUCT((SUBSTITUTE($A$3:$A$10,"1/","")=TRIM(SUBSTITUTE($A14,"Site","")))*($D$3:$D$10=LEFT(F$13,FIND(" ",F$13)-1))*($E$3:$E$10=MID(F$13,FIND(" ",F$13)+1,99))),"")

  13. #13
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Possibly:
    =IF(AND(F$13<>"",$A14<>""),COUNTIFS($A$3:$A$10,"*/"&TRIM(SUBSTITUTE($A14,"Site","")),$D$3:$D$10,LEFT(F$13,FIND(" ",F$13)-1),$E$3:$E$10,MID(F$13,FIND(" ",F$13)+1,LEN(F$13))),"")

    If you have TEXTBEFORE and TEXTAFTER, you could simplify the formula.
    Rory

  14. #14
    Registered User
    Join Date
    04-14-2023
    Location
    United States
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Good Day!!! Thanks for all the help. I tried the formula out and it doesn't seem to work with my master tracker. Is there a way for the formula to look for the "Type III" or "ORV II" in column E. The Formula works great when I am looking a single vehicle like in column D. I need the formula to also generate the number for all Models that are specific to each District / Site like we did previous columns. I do apologize if this getting to be more complicated.

  15. #15
    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,955

    Re: Unable to get COUNTIF Formula to Calculate two columns

    Which formula? Whom are you addressing? Can you provide a more realistic sample dataset for us to work with?

  16. #16
    Registered User
    Join Date
    04-14-2023
    Location
    United States
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Unable to get COUNTIF Formula to Calculate two columns

    My sincerest apologies, I was addressing you AliGW. I am certain the issue is my example tracker. The way I set it up for column F is not accurate to my master tracker which throws off the formula. Please take a look at the new example. I appreciate all the time and effort in helping me.

    Vehicle Inventory 4.xlsx
    Attached Files Attached Files
    Last edited by JB2385; 04-26-2023 at 09:43 AM.

  17. #17
    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,955

    Re: Unable to get COUNTIF Formula to Calculate two columns

    What about Rory's suggestion?

    I see you've shifted the goalposts. We can only provide solutions based on what you tell us and show us. Don't assume that we will imagine all sorts of other eventualities that might exist in your real data. Instead, make sure we have the full facts up front.

    Reconsider your request and provide a sample workbook that is as close to the real data as it possibly can be. I have to tell you that this is the point at which I tend to walk away, as I sense that every time I find a solution, another unexpected wrinkle will be reveealed to me. That's not a lot of fun!
    Last edited by AliGW; 04-26-2023 at 09:55 AM.

  18. #18
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: Unable to get COUNTIF Formula to Calculate two columns

    It would be much simpler if you could enter the criteria into two separate cells, or at least delimit them with something consistent.

  19. #19
    Registered User
    Join Date
    04-14-2023
    Location
    United States
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Unable to get COUNTIF Formula to Calculate two columns

    I understand, I am somewhat experienced with excel but not as experienced as the people on here. I understand the need to walk away and I appreciate all the help AliGW. I did make some errors on the example sheet and I will be sure for the future it is more accurate to limit the back and forth. Rorya I do not disagree that it would be simpler if things were more consistent. Unfortunately this isn't my design per say with inconsistencies on the vehicles, its how the upper management want it. I will go ahead mark this forum as solved and try and figure another way out. I appreciate everyone's input and help!!!!!

  20. #20
    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,955

    Re: Unable to get COUNTIF Formula to Calculate two columns

    There is no need to mark this as solved - it isn't. All I am saying is get your ducks properly in line and then post a properly representative set of data here in THIS thread. If you need a few hours to think this through, that's fine.

    It's just a case of stopping the drip feed and getting everything up front. Make sense?

  21. #21
    Registered User
    Join Date
    04-14-2023
    Location
    United States
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Unable to get COUNTIF Formula to Calculate two columns

    I understand. I will leave this open. The last spreadsheet I posted is the most accurate representation of the master tracker. I would love to just post the master tracker but unfortunately I cannot post it on here due to it being proprietary. Again thanks for all the help and advice on everything.

  22. #22
    Registered User
    Join Date
    04-14-2023
    Location
    United States
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Unable to get COUNTIF Formula to Calculate two columns

    I want to thank everyone for the help and support. The issue has been resolved. Please checkout the updated spreadsheet and I will post the formula that resolved the issue. Thanks again everyone!!

    Formula:

    =IF(AND(F$13<>"",$A14<>""),SUMPRODUCT((SUBSTITUTE($A$3:$A$10,"1/","")=TRIM(SUBSTITUTE($A14,"Site","")))*($D$3:$D$10="ford 1.1")*($E$3:$E$10=TRIM(SUBSTITUTE($F13,"Ford 1.1","")))),"")


    Vehicle Inventory 5.xlsx

+ 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. [SOLVED] Filter formula - unable to look up a certain word from 2 x columns
    By emmagizer in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-04-2021, 06:51 AM
  2. [SOLVED] Unable to calculate columns based on cell values using a SUMIF formula
    By peterjames in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-02-2020, 11:44 AM
  3. Unable to calculate cell text instead of formula, vba not working
    By Pronab20 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-28-2015, 04:40 PM
  4. [SOLVED] Unable to calculate using sumif formula
    By katieshields in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-28-2013, 03:58 AM
  5. Replies: 0
    Last Post: 11-10-2012, 03:42 PM
  6. Replies: 3
    Last Post: 12-13-2009, 11:48 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