Jump to content
Whoosah

How to create a CF ( recursive ) to detect a deadline from a list

Recommended Posts

Whoosah

Hi forum!

 

I'm trying to wrap my head around these Recursive CF's. Figured that I was no longer able to avoid using them, so now I'm giving it a go ... so far: no luck.

 

I have set myself a task:

 

In a list I have a bunch of Deadlines separated by a "¶" eg.:

 

22/10/2008

30/10/2008

21/11/2008

...

 

What I would like to do is for the Custom Function to return a "1" IF at least of the deadlines from the list comes within range of Get ( CurrentDate ) + 30. If no matches are found, the Custom Function should just return a "0".

 

The reason for the "1" and "0" is because I would like some output to trigger some Conditional Formatting in an "Alert Field", something like change the font color to red and the style to italic.

 

 

The Custom Function's name is DEMO, and it takes the parameter of ( deadlines ) which is a list of deadlines coming from a related file.

 

I've written this so far, but I can't seem to figure out what's heads or tails in this.

 

Let (

[

_thelist = List ( deadlines );
_thecount = ValueCount ( _thelist );
_valuetotest = LeftValues ( _thelist; 1 );
_theendofdays = Get ( CurrentDate ) + 30

];

Case ( _thecount; Case ( _valuetotest ≤ _theendofdays; 1; "" & DEMO ( LeftValues ( _thelist; _thecount - 1 ) ) ) )

)

 

I don't know where to put the "0"... and for some reason I don't think I'm getting any recursiveness at all, actually I'm pretty sure I don't.

 

Could someone please guide me in the right direction. I would very much like to get the hang of this.

Share this post


Link to post
Share on other sites
Ender

A couple questions first:

 

What is "deadlines" in your CF above? If it's a parameter, it doesn't make sense to use List() on it. You should probably send in the list of dates instead (put the work of making a list from whatever values in the calc that calls it).

 

What do you mean by "comes within range of get(currentdate) + 30? In your CF, you seem to be including any dates less than (or equal to) the currentdate + 30. What about a date from 2 months ago? Your CF should probably be strict about which two dates define the range. Again, put the work of defining the range on the calc that calls it.

Share this post


Link to post
Share on other sites
Whoosah

Hi!

 

Sorry for not being specific, I'll try to do better ;-)

 

My deadlines are coming from a relationship. I have a project which in theory can have an infinite amount deadlines attached to it. If there is a better way of doing the collecting of deadlines, please let me know.

 

Within range... really bad way of writing things - sorry ... again. I would like to check the

    of deadlines for any one occurrence ( or more ) that is less than or equal to the current date + 30 ( one month ahead ). So if a deadline is i.e. 30/10/2008 it will be caught by the CF because it is less than or equal to current date + 30

     

    Do I make sense now?

     

    Again, I'm a bit in the dark about this one, so any help is appreciated.

Share this post


Link to post
Share on other sites
Ender

As I said, I'd keep the CF general (you might be able to use it elsewhere). One other thing is that list of dates will technically be text, so in order to do comparisons, you'll need to explicitly convert each one to a date.

 

Here's my first shot at this (untested):

 

//DatesContainedInRange(listOfDates; rangeStart; rangeEnd) =

 

let(

[

n = valuecount(listOfDates);

topDate = getasdate(getvalue(listOfDates;1))

];

case(n>0;

case(topDate ≥ rangeStart and topDate ≤ rangeEnd;1) +

DatesContainedInRange(rightvalues(listOfDates;n-1); rangeStart; rangeEnd)

)

)

)

 

To call it, you'd use List() to create the list of dates based on the related values, give it an arbitrary rangeStart that will be before any possible dates in your set, and an rangeEnd that's the current date + 30:

 

DatesContainedInRange(list(deadlines::date); date(1;1;1900); get(currentdate) +30)

 

The value returned is the number of "hits" (dates in the range). If it's greater than zero, there is at least one.

 

Note: With the type of recursion in here, I think you'll be limited to 10,000 iterations (dates).

Share this post


Link to post
Share on other sites
David Head

This is probably not the best use of a CF. I feel that it could be done more easily with a filtering relationship and then if you want, return a list of dates from that relationship.

 

Question is, what do you want to do with the list of dates once you have them?

Share this post


Link to post
Share on other sites
This thread is quite old. Please start a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...

Important Information

Terms of Use