+ Reply to Thread
Results 1 to 18 of 18

adding additional condition in calculating 5 most frequent string values

Hybrid View

  1. #1
    Registered User
    Join Date
    11-04-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    18

    adding additional condition in calculating 5 most frequent string values

    Dear forums members. I need your help in upgrading a formula that I use to calculate 5 most frequent string values. I use this formula on a database that has two groups of participants. Now I need to make the same calculation for group 1 only, which is probably requires adding additional IF into the formula. I couldn't figure out how to make this work. Your help would be very much appreciated.
    A demo file is attached. I have to calculate into "asylum seekers only" sheet. The total for all participants is calculated in "calculation" sheet.
    Thank you

    Marina

  2. #2
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: adding additional condition in calculating 5 most frequent string values

    If Excel in Office 365 ProPlus handles spilled formulas, dynamic arrays, and includes the newer worksheet functions, you should be able to use a single formula to populate calculation!D3:I3, namely

    =INDEX(UNIQUE(SORTBY(country,COUNTIFS(country,country),-1)),SEQUENCE(1,6))

    and calculation!J3:O3 using

    =INDEX(UNIQUE(SORTBY(language5,COUNTIFS(language5,language5,language5,"<>other"),-1)),SEQUENCE(1,6))

    The latter is longer because you seem to exclude other, which is more numerous than Pashtu or Arabic.

    To add a condition for only asylum seekers, add to the COUNTIFS calls' conditions.

    'asylum seekers only'!D3:I3:
    =INDEX(UNIQUE(SORTBY(country,COUNTIFS(country,country,data!$D$4:$D$149,"Asylum Seeker"),-1)),SEQUENCE(1,6))

    'asylum seekers only'!J3:O3:
    =INDEX(UNIQUE(SORTBY(language5,COUNTIFS(language5,language5,language5,"<>other",data!$D$4:$D$149,"Asylum Seeker"),-1)),SEQUENCE(1,6))

  3. #3
    Registered User
    Join Date
    11-04-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    18

    Re: adding additional condition in calculating 5 most frequent string values

    Hi hringrv
    Thank you for your help
    I was not able to make your suggested formula work. It returns NAME.
    Using the formula in file, I was trying to add the argument : data!$D$4:$D$149,"Asylum Seeker" to calculate D4:
    =COUNTIF(country,D3,data!$D$4:$D$149,"Asylum Seeker") - it returns "you have too many arguments"
    Any ideas how to resolve this?
    Regards
    Marina

  4. #4
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: adding additional condition in calculating 5 most frequent string values

    Quote Originally Posted by Marina Kunin View Post
    . . . I was not able to make your suggested formula work. It returns NAME.
    What does =INFO("Version") return? What does =SORTBY({2;1},{1;2},-1) return?

    . . . I was trying to add the argument : data!$D$4:$D$149,"Asylum Seeker" to calculate D4:

    =COUNTIF(country,D3,data!$D$4:$D$149,"Asylum Seeker")

    . . . it returns "you have too many arguments"
    Use COUNTIFS rather than COUNTIF.

  5. #5
    Registered User
    Join Date
    11-04-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    18

    Re: adding additional condition in calculating 5 most frequent string values

    Thank you hringrv
    CONTIFS solves the problem in D4:I4, but because D3:I3 are incorrect, as they are calculated for the whole group, not only asylum seekers, the calculation is wrong

  6. #6
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: adding additional condition in calculating 5 most frequent string values

    Please see this workbook on OneDrive.

  7. #7
    Registered User
    Join Date
    11-04-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    18

    Re: adding additional condition in calculating 5 most frequent string values

    Thanks hringrv
    I do not know what is the problem, but it does not work for me. Please see the attached file - the formula returns NAME?
    Regards
    Marina

  8. #8
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: adding additional condition in calculating 5 most frequent string values

    I'll look at your file, but what does =INFO("release") return on your system? I want to make sure what features you have.

  9. #9
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: adding additional condition in calculating 5 most frequent string values

    OK, simpler and avoiding any functions which aren't in Excel 2010.

    I'd add supplemental calculations in the data worksheet.

    O4: =MATCH(E4,country,0)
    P4: =MATCH(F4,language5,0)/(F4<>"other")
    R4: =MATCH(E4,country,0)/(D4="Asylum Seeker")
    S4: =MATCH(F4,language5,0)/(F4<>"other")/(D4="Asylum Seeker")

    Select O4:S4 and fill down into O5:S149. These return index of first match for country or language for the country or language on a given row and errors for blank cells or failing to meet inclusion criteria. ERROR RETURN VALUES ARE INTENTIONAL.

    Then in the calculation worksheet,

    D3: =INDEX(country,MODE(IFERROR(data!$O$4:$O$149,FALSE)))
    E3: =INDEX(country,MODE(IFERROR(data!$O$4:$O$149/(1-SIGN(COUNTIF($D3:D3,country))),FALSE)))

    Fill E3 right into F3:I3.

    J3: =INDEX(language5,MODE(IFERROR(data!$P$4:$P$149,FALSE)))
    K3: =INDEX(language5,MODE(IFERROR(data!$P$4:$P$149/(1-SIGN(COUNTIF($J3:J3,language5))),FALSE)))

    Fill K3 right into L3:O3.

    Then on the asylum seekers only worksheet

    D3: =INDEX(country,MODE(IFERROR(data!$R$4:$R$149,FALSE)))
    E3: =INDEX(country,MODE(IFERROR(data!$R$4:$R$149/(1-SIGN(COUNTIF($D3:D3,country))),FALSE)))

    Fill E3 right into F3:I3.

    J3: =INDEX(language5,MODE(IFERROR(data!$S$4:$S$149,FALSE)))
    K3: =INDEX(language5,MODE(IFERROR(data!$S$4:$S$149/(1-SIGN(COUNTIF($J3:J3,language5))),FALSE)))

    Fill K3 right into L3:O3.

    The formulas in calculation and asylum seekers only worksheets may all need to be entered as array formulas if your version of Excel doesn't support spilled formulas.

  10. #10
    Registered User
    Join Date
    11-04-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    18

    Re: adding additional condition in calculating 5 most frequent string values

    thank you
    Marina

  11. #11
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: adding additional condition in calculating 5 most frequent string values

    Try this . Pl see file.
    In D2 and copied across

    =INDEX(country,MODE(IF((country<>"")*(COUNTIF($A$2,Refugee)>0)*ISNA(MATCH(country,$C$3:C$3,0)),MATCH(country,country,0) * {1,1})))

    In D3 and copied across


    =COUNTIFS(country,D3,Refugee,$A$2)
    Last edited by kvsrinivasamurthy; 02-10-2020 at 02:21 PM.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  12. #12
    Registered User
    Join Date
    11-04-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    18

    Re: adding additional condition in calculating 5 most frequent string values

    Thank you kvsrinivasamurthy, this is very helpful. Can you just explain what you did in A2?
    Thanks
    Marina

  13. #13
    Registered User
    Join Date
    11-04-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    18

    Re: adding additional condition in calculating 5 most frequent string values

    Ooh! I figured it out. This is clever ! Thank you kvsrinivasamurthy

  14. #14
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: adding additional condition in calculating 5 most frequent string values

    Thanks for feedback and rep.

  15. #15
    Registered User
    Join Date
    11-04-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    18

    Re: adding additional condition in calculating 5 most frequent string values

    Dear forums members. I have to reopen this thread. I need your help in upgrading the formula that I use to calculate 5 most frequent string values. I want to exclude "other" value from the calculation. I couldn't figure out how to make this work. Your help would be very much appreciated.
    A demo file is attached. Here is the formula:
    =INDEX(country,MODE(IF((country<>"")*(COUNTIF($A$2,Refugee)>0)*ISNA(MATCH(country,$C$3:C$3,0)),MATCH(country,country,0) * {1,1})))
    Attached Files Attached Files

  16. #16
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2504
    Posts
    19,086

    Re: adding additional condition in calculating 5 most frequent string values

    If I understand the request correctly then make the following modification to the array entered formula*:
    Formula: copy to clipboard
    =INDEX(country,MODE(IF((country<>"")*(country<>"other")*(COUNTIF($A$2,Refugee)>0)*ISNA(MATCH(country,$C$3:C$3,0)),MATCH(country,country,0) * {1,1})))

    *Remember to press Ctrl, Shift and Enter to activate.
    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  17. #17
    Registered User
    Join Date
    11-04-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    18

    Re: adding additional condition in calculating 5 most frequent string values

    Yes, it works! Thank you so much JeteMc

  18. #18
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2504
    Posts
    19,086

    Re: adding additional condition in calculating 5 most frequent string values

    You're Welcome and thank you for the feedback. Please take a moment to mark the thread as 'Solved' using the thread tools menu above your first post. I hope that you have a blessed day.

+ 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] Adding an additional Condition to a working Formula
    By hammer2 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-29-2016, 06:58 AM
  2. Adding additional IF condition
    By dannyjoer in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-28-2014, 10:10 AM
  3. Adding additional Values to a Bar chart
    By ivanlm78 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 12-02-2013, 06:15 PM
  4. Macro to format data - counting and adding additional rows on condition
    By rynofrowan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-12-2013, 11:46 PM
  5. Replies: 3
    Last Post: 03-20-2012, 09:53 PM
  6. Adding additional string to formula
    By rhudgins in forum Excel General
    Replies: 2
    Last Post: 06-23-2011, 03:38 PM
  7. Adding additional columns and values based on the given data
    By nynamyna in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2011, 05:22 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