+ Reply to Thread
Results 1 to 10 of 10

Switch Function - Two Criteria or Expressions

Hybrid View

  1. #1
    Registered User
    Join Date
    04-04-2013
    Location
    Hoboken, NJ
    MS-Off Ver
    Excel 365
    Posts
    28

    Switch Function - Two Criteria or Expressions

    Hi All,

    I recently discovered the Switch Function and it is remarkable. I am able to get what I need based on one expression, but I haven't been able to wrap my head around basing off of two sets of criteria or expressions.

    The attached is College Football and I want to find the Top 5 impressions per week. Cell B334 is where I am writing my formula, referencing Cell B333 as my initial criteria/expression, where I can toggle between the weeks using the scroll bar. In addition to seeing what the Top 5 impressions per week are, I'd like to be able to see the Top N impressions per week by Conference, referencing Cell C328. For example which Big Ten game had the highest impressions in Week 10. Right now, I only know which Week 10 game had the highest impressions among all of the games. I searched around and saw some posts about starting with an IF statement or doing a SWITCH TRUE, but I am punting it here to see if there is a better way because I couldn't get those to work.

    Thank you!

    BTray90

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,296

    Re: Switch Function - Two Criteria or Expressions

    You really don't need SWITCH - it is way too much work.

    Use this in B334 (clear out 5 columns and 5 rows for the spilled values)

    =TAKE(SORT(FILTER(HSTACK(M:M,H:H,I:I,A:A,B:B),N:N=B333),1,-1),5)

    and this in B342 (Clear out 5 columns and 10 rows)

    =TAKE(SORT(FILTER(HSTACK(M:M,H:H,I:I,A:A,B:B),ISNUMBER(M:M)),1,-1),10)

    You can add/change additional filters to your data to look at conferences, for example, by changing ISNUMBER(M:M) to J:J=C328 (I think that is where you want conference) or use both with logic like (N:N=B333)*(J:J=C328)
    Last edited by Bernie Deitrick; 11-06-2024 at 03:19 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    04-04-2013
    Location
    Hoboken, NJ
    MS-Off Ver
    Excel 365
    Posts
    28

    Re: Switch Function - Two Criteria or Expressions

    Thanks for taking a look at this, Bernie. I wasn't able to get it to work. I cleared out the Rows/Columns from my previous work and am getting a circular reference, for both formulas. I don't know what is overlapping. Also, what does the -1 represent?

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,296

    Re: Switch Function - Two Criteria or Expressions

    Try entering the formula to the right of your data or onto aother sheet - that should take care of any circular references: that is generally a better workbook design, separating data from analysis/extract.

    The -1 just means to sort the data in descending order....

  5. #5
    Forum Contributor John Vergara's Avatar
    Join Date
    01-17-2022
    Location
    Colombia
    MS-Off Ver
    365
    Posts
    209

    Re: Switch Function - Two Criteria or Expressions

    Hi everyone!

    You can use this two formulas:

    PHP Code: 
    [B334] : =TAKE(SORT(FILTER(CHOOSECOLS(A7:M327,13,8,9,10,2),N7:N327=B333),,-1),5)
    [
    B342] : =TAKE(SORT(CHOOSECOLS(A7:M327,13,8,9,10,2),,-1),10
    The second option assumes that all your data belongs to year 2024 (you can add a 2024 filter if you consider it necessary). Blessings!
    Last edited by John Vergara; 11-06-2024 at 03:48 PM.
    A out-of-context text is a pretext.
    Consider adding reputation points to all the people who help you with your question/problem.

  6. #6
    Registered User
    Join Date
    04-04-2013
    Location
    Hoboken, NJ
    MS-Off Ver
    Excel 365
    Posts
    28

    Re: Switch Function - Two Criteria or Expressions

    Hi John, Thanks for taking a look at this. I was able to get both formulas to work! Really cool how much more simple that is. However, I am not clear on how to apply the 2nd condition/expression where I would like to see a similar Rank of Impressions by a particular week (Cell B333) AND by Conference (Cell C328). For example, what are the top 5 impressions in Week 9 by BIG TEN

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,296

    Re: Switch Function - Two Criteria or Expressions

    Using the filter criteria (N:N=B333)*(J:J=C328) does the week and conference filter

  8. #8
    Registered User
    Join Date
    04-04-2013
    Location
    Hoboken, NJ
    MS-Off Ver
    Excel 365
    Posts
    28

    Re: Switch Function - Two Criteria or Expressions

    That works and I was able to figure out a way to get the ranker underneath the table by fixing the range so there isn't a circular reference. Your formula worked for the Week * Conference. Thank You!
    Bonus Point, anyway to fix the formula for the user to be able to look at a total Top 5, irrespective of the conference, and then look at a Top 5 with the Conference filter in a separate click. I'd like for it to be housed in the same table. I know I could build two rankers, but think it would be cleaner to have one table of rankers that can do those two functions. For example, if the Conference cell is blank in C328, could that default to being No Conference and results would be Total Top 5? Probably a stretch, but wondering if there is another component to switch off one if blank (or some other function) while also being able to apply if there is text in Cell C328 when requested.

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,296

    Re: Switch Function - Two Criteria or Expressions

    Use a filter like

    (N1:N330=B333)*(IF(C328="",TRUE,J1:J330=C328))

  10. #10
    Registered User
    Join Date
    04-04-2013
    Location
    Hoboken, NJ
    MS-Off Ver
    Excel 365
    Posts
    28

    Re: Switch Function - Two Criteria or Expressions

    So simple, so amazing! Thanks Bernie! This will have widespread applications. I will credit you with the reputation and close out the thread.

+ 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] Switch ON/OFF with the IF function
    By Joe.Mintsa in forum Excel General
    Replies: 1
    Last Post: 01-13-2023, 04:58 PM
  2. Single Button Toggle Switch To Switch Between Columns
    By Zaerick in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-29-2022, 11:55 PM
  3. [SOLVED] why switch() function when I can use If()
    By lastnn30 in forum Excel General
    Replies: 1
    Last Post: 12-04-2021, 10:13 PM
  4. Help needed with expressions with substring expressions.
    By sbell1234 in forum Access Tables & Databases
    Replies: 7
    Last Post: 06-21-2015, 02:59 PM
  5. Switch Between alternative lists based on other list or criteria
    By chaddug in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-12-2012, 03:17 PM
  6. Replies: 0
    Last Post: 09-02-2011, 10:47 AM
  7. Switch function
    By kramer.newsreader@gmail.com in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-16-2006, 05:25 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