REGGIE MAGER Posted December 12, 2008 Posted December 12, 2008 Hi. I was wondering if someone could help with a question I have. I'm trying to do a calculation that needs to find a range of dates. If the date is between 1-1-2009 and 3-31-2009 then it needs to return a statement like "1-1-2009 through 3-31-2009" and then the if statement has to continue and do the same for April -Jun, Jul-Sept, and October-December. I've tried it, but everyting I try always ends up returning everything after 1-1-2009. Any help would be greatly appreciated.
Lee Smith Posted December 12, 2008 Posted December 12, 2008 Do you know how to do a search for a Range?
Raybaudi Posted December 12, 2008 Posted December 12, 2008 Case( YourDateField ≤ Date ( 12 ; 31 ; 2008 ) ; "" ; YourDateField ≤ Date ( 3 ; 31 ; 2009 ) ; "1-1-2009 through 3-31-2009" ; YourDateField ≤ Date ( 6 ; 30 ; 2009 ) ; "4-1-2009 through 6-30-2009" ; YourDateField ≤ Date ( 9 ; 30 ; 2009 ) ; "7-1-2009 through 9-30-2009" ; YourDateField ≤ Date ( 12 ; 31 ; 2009 ) ; "10-1-2009 through 12-31-2009" )
comment Posted December 12, 2008 Posted December 12, 2008 If I understand this correctly, you don't need an if statement: Let ( [ m = Month ( YourDate ) ; y = Year ( YourDate ) ] ; Date ( 3 * Div ( m - 1 ; 3 ) + 1 ; 1 ; y ) & " through " & Date ( 3 * Div ( m - 1 ; 3 ) + 4 ; 0 ; y ) )
Raybaudi Posted December 12, 2008 Posted December 12, 2008 Because the question isn't on searching in a range.
Raybaudi Posted December 12, 2008 Posted December 12, 2008 If I understand correctly, she has many records with dates but wants that calc only for the year 2009.
REGGIE MAGER Posted December 12, 2008 Author Posted December 12, 2008 Thank you for the help. That works great. And I learned a lot from your solution. It was frustrating because I thought I needed an If caluclation. This is so easy. Thanks again.
LaRetta Posted December 13, 2008 Posted December 13, 2008 (edited) What if y < 2009 or y > 2009 ? Simply wrap Comment's calc with an If() or Case () like: [color:green]If ( Year ( YourDate ) = 2009 ; Let ( [ m = Month ( YourDate ) ; y = Year ( YourDate ) ] ; Date ( 3 * Div ( m - 1 ; 3 ) + 1 ; 1 ; y ) & " through " & Date ( 3 * Div ( m - 1 ; 3 ) + 4 ; 0 ; y ) ) [color:green]) But it doesn't make much sense to limit the calc when it would automatically work whenever, whereever one would want it to, whenever viewed. It is obviously a calc for display purposes only. Michael - I didn't mean to alter your calc which is perfect as it stands. I just wanted to produce an example of how; also indicating it wouldn't be necessary (from what I can tell). Edited December 13, 2008 by Guest Added sentence
comment Posted December 13, 2008 Posted December 13, 2008 We build to last. Now, seriously: if someone wanted a calculation that only returns a result for 2009, I would tell them to rethink their strategy. Because "2009" is data - and it doesn't belong in a calculation formula, which is part of the schema.
Recommended Posts
This topic is 5883 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now