+ Reply to Thread
Results 1 to 9 of 9

How to calculate percentage based on conditions

  1. #1
    Registered User
    Join Date
    01-24-2013
    Location
    HELL
    MS-Off Ver
    Excel 2010
    Posts
    14

    How to calculate percentage based on conditions

    Hi everyone,

    I am so close to solving this formula but I can't figure it out. Please help!

    Please see the attached sample excel

    What I want to happen is that when you filter "YEAR" for either 2016 or 2017, I want Table 2. to automatically calculate the percentage of YES=1 from column "Y/N" but ONLY OUT OF the total responses for the specified site indicated in Table 2.

    So for example, if you filter YEAR for 2017, in Table 2. the percentage for site TWH should show up as 50% b/c there is only one 1 out of 2 responses for TWH.

    Similarly, for site BAR, in Table 2 the percentage should be 60%.

    However, what is happening, is that the formula in Table 2. is calculating the number of Yes=1 for each site out of ALL the responses in the Y/N column.

    I hope this make sense. Someone please help I am so damn close!
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: How to calculate percentage based on conditions

    I don't understand how you are getting 60%? 42.86% seems correct to me. You have 7 visible, 3 of which are BAR and y/n = 1.

    3/7 = 0.428571

  3. #3
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: How to calculate percentage based on conditions

    Sorry, misunderstood. here you go.

    =SUM(COUNTIFS($B$1:$B$12,"BAR", $C$1:$C$12,1,$D$1:$D$12,1)/COUNTIFS($B:$B,"BAR",$D:$D,1))
    =SUM(COUNTIFS($B$1:$B$12,"TWH", $C$1:$C$12,1,$D$1:$D$12,1)/COUNTIFS($B:$B,"TWH",$D:$D,1))
    Last edited by DannyJ; 03-23-2017 at 10:56 AM.

  4. #4
    Registered User
    Join Date
    01-24-2013
    Location
    HELL
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: How to calculate percentage based on conditions

    Hi DannyJ!

    Thank you!, but this is weird...when I enter the exact same formula into the TWH column in Table 2, it's given me the incorrect percentage. I'm getting 33.33% when it should be 50% b/c there is only one yes out of 2 responses for site TWH.

    I changed the quotations to "TWH" instead of "BAR" and kept everything else the same. I'm not exactly sure what I'm doing wrong...

    do you know? I don't even get why it's 33.33%? How is it getting that!

  5. #5
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: How to calculate percentage based on conditions

    I'm having success with the following in M22, filled right:

    =IFERROR(SUMPRODUCT(--($B$2:$B$12=M$21),($C$2:$C$12=1)*($D$2:$D$12))/(SUM($D$2:$D$12)-COUNTIFS($D$2:$D$12,1,$B$2:$B$12,"<>"&M$21)),0)
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,189

    Re: How to calculate percentage based on conditions

    Try

    in M22 and copy across

    =SUMIFS($C:$C,$A:$A,$N$20,$B:$B,M21)/COUNTIFS($B:$B,M21,$A:$A,$N$20)

    "Year" in a drop-down (2016/2017) in N20
    Last edited by JohnTopley; 03-23-2017 at 11:26 AM.

  7. #7
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: How to calculate percentage based on conditions

    I have attached the spreadsheet with the formula as I sent them. I think you may be using the formula before I edited the post.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    01-24-2013
    Location
    HELL
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: How to calculate percentage based on conditions

    Quote Originally Posted by DannyJ View Post
    Sorry, misunderstood. here you go.

    =SUM(COUNTIFS($B$1:$B$12,"BAR", $C$1:$C$12,1,$D$1:$D$12,1)/COUNTIFS($B:$B,"BAR",$D:$D,1))
    =SUM(COUNTIFS($B$1:$B$12,"TWH", $C$1:$C$12,1,$D$1:$D$12,1)/COUNTIFS($B:$B,"TWH",$D:$D,1))
    Thank you! this works now!


    sorry, one more question.

    I'm trying to make these formulas work on a different sheet in excel. So all my data is on a sheet called "DATA"-which is where this formula is pulling everything from. However, I want to put this formula on a different sheet. How do I make this formula work by referencing the DATA sheet? I can't seem to put the sheet name DATA in the correct placement in the formula to make it work.

    I'm so sorry and thank you for all your help!

  9. #9
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: How to calculate percentage based on conditions

    No worries. Assuming everything is on the data tab, I believe it would be:

    =SUM(COUNTIFS(Data!$B$1:$B$12,"BAR", Data!$C$1:$C$12,1,Data!$D$1:$D$12,1)/COUNTIFS(Data!$B:$B,"BAR",Data!$D:$D,1))

+ 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. Replies: 3
    Last Post: 01-04-2017, 10:20 AM
  2. Replies: 2
    Last Post: 01-03-2017, 02:12 PM
  3. [SOLVED] Calculate percentage based on data
    By mathanraj76 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-04-2016, 04:25 PM
  4. [SOLVED] Calculate number based on percentage
    By Manish Bajpai in forum Excel Formulas & Functions
    Replies: 22
    Last Post: 09-06-2005, 06:05 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