+ Reply to Thread
Results 1 to 8 of 8

Help with CSE formula (MODE-IF)

  1. #1
    Registered User
    Join Date
    08-12-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2010
    Posts
    20

    Question Help with CSE formula (MODE-IF)

    Hello -

    I'm not sure what I'm trying to do is possible. I've attached a small spreadsheet. It contains 2 columns with data and a CSE formula in cell D1. What I'm trying to do is get the mode given a condition. The CSE formula works as is, but what I'm hoping to do is allow for some flexibility in the range.

    For instance, I have 9 rows of data right now, but I'm trying to integrate this into a program I'm writing, and the number of rows constantly changes so the range can't be a set number of cells. In cell D3 is what I'm hoping to achieve, but it seems when I try to use entire columns I get a "#NUM!" error.

    Any thoughts or suggestions?

    Thanks!
    Attached Files Attached Files
    Last edited by tom_19; 08-17-2011 at 03:06 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Help with CSE formula (MODE-IF)

    Create a named range, through Formulas tab | Define Name.

    Call it DataRange and assign the formula:

    =Sheet1!$A$1:INDEX(Sheet1!$B:$B,COUNTA(Sheet1!$A:$A))

    then your Mode function becomes:

    =MODE(IF(INDEX(DataRange,0,1)="TX",INDEX(DataRange,0,2)))
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Help with CSE formula (MODE-IF)

    Your profile indicates you have Excel 2010.

    If that's true, you could convert your data range to a table.
    Then you could use an array-formula like this to calculate the MODE while automatically adjusting for changes in the data range
    =MODE(IF(Table1[[#All],[State]]="TX",Table1[[#All],[Amount]]))

    (see the attached workbook)

    Is that something you can work with?
    Attached Files Attached Files
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Registered User
    Join Date
    08-12-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Help with CSE formula (MODE-IF)

    Thanks for the help and quick replies! I tried NBVC's suggestion and it worked beautifully!

    Ron, I am using Excel 2010 at home, but my office (who will be using my program) runs Excel 2003 still. For this reason, I imagine I should probably stick with the DataRange suggestion over your Table suggestion for compatibility issues, right?

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Help with CSE formula (MODE-IF)

    Quote Originally Posted by tom_19 View Post
    Thanks for the help and quick replies! I tried NBVC's suggestion and it worked beautifully!

    Ron, I am using Excel 2010 at home, but my office (who will be using my program) runs Excel 2003 still. For this reason, I imagine I should probably stick with the DataRange suggestion over your Table suggestion for compatibility issues, right?
    Absolutely, yes!

  6. #6
    Registered User
    Join Date
    08-12-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Help with CSE formula (MODE-IF)

    Hmm, wondering if I could trouble either one of you for further clarification on this issue? After your replies, I quickly tested this and had no trouble, but now I've gotten a little further and am running into an issue.

    I've attached a workbook called "test file." I stripped out all of my data except what I'm working with to do this CSE formula. On the 'Variables' worksheet, I'm trying to write 3 separate CSE formulas to find the modes based on the data on the 'Aged Invoices' worksheet. I have 3 accounts I'm doing this for. The first 2 (510300 and 10020037) are working fine, but the last 1 (10021991) is giving me an "#N/A" error, and I'm not sure why. It should be returning a result of 30.
    Attached Files Attached Files

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Help with CSE formula (MODE-IF)

    Since you are starting the the numbering at A4 instead of A1, we need to adjust the Named range formula a bit, to offset the header rows... so change the DataRange formula to:


    ='Aged Invoices'!$A$4:INDEX('Aged Invoices'!$I:$I,COUNTA('Aged Invoices'!$A:$A)+2)

  8. #8
    Registered User
    Join Date
    08-12-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Help with CSE formula (MODE-IF)

    That did it! Thanks!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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