Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 23

Thread: Frequency function and open intervals

  1. #1
    VBAX Regular
    Joined
    Jul 2009
    Posts
    26
    Location

    Frequency function and open intervals

    Hi

    I'm trying to count how many people that have salaries that are within a certain range. I would like to use the frequency function but I can't figure out how to use open intervals. For instance I have an interval of [400.000 ; 425.000[ (meaning 400.000 is within the interval but 425.000 is not). How do I use the frequency function so that it counts all salaries equal to 400.000 and above 400.000 but below 425.000?

    Right now I'm using the countif function as follows
    [vba]COUNTIF(Sheet1!J$2:J$33;"<425000")-B30[/vba] [vba]B30 = COUNTIF(Sheet1!J$2:J$33;"<400000")-B29 [/vba] and so forth so that I extract all numbers below 400.000.
    Although the countif function seems as a suitable replacement for the frequency function it appears that it produces wrong results.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    How about

    =COUNTIF(J$2:J$33,">=400000")-COUNTIF(J$2:J$33,">=425000")
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Using frequency
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Regular
    Joined
    Jul 2009
    Posts
    26
    Location
    Thank you for your fast replies. Unfortunately I have to leave work now but I'll look more into your solutions tomorrow.

  5. #5
    VBAX Regular
    Joined
    Jul 2009
    Posts
    26
    Location
    Now I've taken a closer look at both your solutions.

    xld: you suggest that I count the instances within the range [400.000 ; eternity[ and then subtract the range [425.000 ; eternity[. I believe the interval I end up with is [400.000 ; 425.000[ which is exactly what I need.

    mdmackillop: you suggest using the frequency function which I would prefer so that the users of the sheet easily can understand the function. But isn't it a wrong interval? I think that the frequency function uses this interval ]400.000 ; 425.000] but I need the interval of [400.000 ; 425.000[. From what I gather from your countif function you count the instances within the interval ]eternity ; 425.000] and then subtract the interval ]eternity ; 400.000]. But then you end up with the interval of ]400.000 ; 425.000] instead of [400.000 ; 425.000[.

    So I guess my question still is: is there any way that I can use the frequency function when I want to count the lowest number in the interval (400.000) and not the highest number in the interval (425.000)?

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If I understand you correctly.
    Change the 425,000 figure to a large number =10^10 or =MAX(B:B). Clear the remaining values.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by nicosdj
    xld: you suggest that I count the instances within the range [400.000 ; eternity[ and then subtract the range [425.000 ; eternity[. I believe the interval I end up with is [400.000 ; 425.000[ which is exactly what I need.
    Not quite, it is [400.000 ; 424.999,99[

    Quote Originally Posted by nicosdj
    So I guess my question still is: is there any way that I can use the frequency function when I want to count the lowest number in the interval (400.000) and not the highest number in the interval (425.000)?
    Do you mean just the 4000.000 figure, or [400.000 ; 424.999,99[. If the latter, that is what mine does.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Regular
    Joined
    Jul 2009
    Posts
    26
    Location
    Mdmackillop: I'm sorry but I don't quite understand that. How exactly would the frequency function look?

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The interval are entered into a range. They need not be eqally spaced. You could have only 4 values such as 0, 400,000, 425,000 and =Max(B:B)

    If you could post a workbook showing your layout and criteria that would clarify things
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    VBAX Regular
    Joined
    Jul 2009
    Posts
    26
    Location
    xld: I think your solution covers the interval I need. But I don't see why it is the [400.000 ; 424.999,99[ interval that is covered - maybe we misunderstand each other because of the brackets and the different ways of defining intervals?

    When I type [400.000 ; 425.000[ I define the interval: 400.000=< x <425.000 where x is a salary and I then count the number of x'es that fulfill the condition. The interval can also be written as [400.000 ; 425.000).

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Because I subtraact all numbers greater than or EQUAL to 425000.

    Set a value to exactly 425000 and try it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  12. #12
    VBAX Regular
    Joined
    Jul 2009
    Posts
    26
    Location
    Here goes. Sorry I didn't do that to begin with...

  13. #13
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No data in the workbook.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  14. #14
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Like so?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  15. #15
    VBAX Regular
    Joined
    Jul 2009
    Posts
    26
    Location
    Thanks to you both!

    The frequency function works fine in the sample you've provided mdmackillop (although I don't understand why).
    In the attached workbook I've looked at your countif function and tested with a "TÆL.HVISER" (don't know the english version) function as well. The numbers are all equal so that's good - I just wish I understood exactly how it worked.


    I should have done it in vba - it would have been so much simpler


    Thanks again!

  16. #16
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by nicosdj
    In the attached workbook I've looked at your countif function and tested with a "TÆL.HVISER" (don't know the english version) ...
    TÆL.HVIS is COUNTIF so I assume TÆL.HVISER is 2007 COUNTIFS.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  17. #17
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The frequency formula looks wrong to me, 425000 gets added to the wrong set. Change 610155 to 425000 and you will see 425000 go up to 80 whereas COUNTIF and COUNTIFS changes 45000 to 84.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  18. #18
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    And the frequency formula is an array formula, so much slower.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  19. #19
    VBAX Regular
    Joined
    Jul 2009
    Posts
    26
    Location
    xld: Thanks for checking! You're right - 425.000 does indeed get added to the wrong set. I guess it isn't possible for me to use the frequency function then.

  20. #20
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You would have to change the intervals to 424999.99 from 425000 etc.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •