What's the equivalent of $ChildCount(if...)?


(James Fallows) #1

I assume there is a simple answer to this, but I don’t know (or remember) what it is, and can’t immediately find it in the material:

  • I have a large number of notes in a container, and the notes all have a Boolean attribute – let’s call it $CountMe.
  • I want to display, in the $Text of the parent container-note, a count of how many of the child notes have $CountMe set to true. For instance, if there are 100 notes total, and 25 have that attribute set, I’d like to see 25.
  • If I didn’t care about that attribute, I could just use $ChildCount to produce a total of all child notes. If I were wanting to get the actual values for the notes, I could use collect_if I understand each of these procedures.

But what is the equivalent to $ChildCount(if) or childcount_if (knowing that neither of those is the right way). How do I find the number of child notes meeting a condition? Thanks.


(Mark Anderson) #2

$MyNumber = sum_if(children,$CountMe,1);

More pedantically:

$MyNumber = sum_if(children,$CountMe==true,1);


(James Fallows) #3

Excellent, thank you!


(Rigas Arvanitis) #4

Fine !

So, now I want to change the name of the container that has this number $MyNumber with a $Name that is :

$MyNumber = sum_if(children,$CountMe==true,1) ; if($ChildCount){$Name+" ("+$ChildCount+") and “+ $MyNumber + " urgent tasks” }else{$Name}

And nothing happens !

Whereas before I had ) ;

if($ChildCount){$Name+" ("+$ChildCount+")" }else{$Name}

and it worked…
What is wrong here?


(Mark Anderson) #5

This doesn’t work for me as a rule or edit - and likely for the same reason the new code doesn’t work because the if result doesn’t set it’s output to anything. Therefore I suspect you are using a display expression, rather than a rule. The latter is relevant because the display expression is intended to be a single (and ideally non-complex) single expression. Thus you needs to split the new code. Set the note (or prototype’s) $Rule to:

$MyNumber = sum_if(children,$CountMe==true,1);

Set the $DisplayExpression to:

if($ChildCount){$Name+" ("+$ChildCount+") and "+ $MyNumber + " urgent tasks" }else{$Name};

And it works - at least it does when tested here in v7.2.2.


(Mark Anderson) #6

I’ve updatedmy page on Display Expressions to reflect some of the issues raised above, such as not trying to stick multiple expressions into $DisplayExpression.


(Rigas Arvanitis) #7

Yes Mark., its a display expression of the container $Name
I did what you recommend and it works fine on v6.2.0

Thank you - for as always so useful help

Rigas


(Rigas Arvanitis) #8

Yes - an error I was doing too often.


(Mark Anderson) #9

No worries, nothing got seriously broken and all seems fixed now, plus it’s enabled me to improve my notes for others to follow. A win-win. :slight_smile: