Tinderbox Forum

Extracting the values from other notes to use in a report

Hi, I need some help in how to extract information from a data set for a report I am writing.

I have a data set of 156 members of an organisation. Per person it contains Attributes like $Age_2020, $Gender etc. Some of them (like $Age_2020) are numeric, and hence want to write about their minimums, maximums and averages.

Say I want to write a sentence like “The age of the members is between 37 and 95 years”, but refer to the data to produce the numbers. Assume my member notes are children of a note “MemberLIst”, and the numeric attribute I want to refer to is in $Age_2020.

How could I extract the numbers? I tried asking for the minimum / maximum of the list of notes that are descendants of the main note. With the help of aTbRef I tried to piece something together:

^value(min(list(descendants, "MemberList")))^ and ^value(max(list(descendants, "MemberList"))^

but that would not work. Obviously, what is missing is reference to the Attribute $Age_2020 - but where would I put that in?

Any help gratefully accepted! (And while you’re at it: my next wish is to find out the average age, using the same variable…)

Many thanks!

As you have anticipated, you’ll begin by collecting a list of the ages of the members.

$MyList=collect(children(/MemberList), $Age_2020)

The first argument indicates from where you want to collect things; here, I’ve said “from the children of the top-level container named “MemberList”.

The second argument is the attribute we want to collect.

I’m storing this list in $MyList because we want to use it at least twice; that way, we only need to build it once. Also, we can look at $MyList to see if it contains what we expect!

Now, we can export this easily enough:

The age of the members is between 
^value($MyList.min) and ^value($MyList.max)

It turns out that the syntax for the average is a little more involved; it’s like collect:

$MyNumber=avg(children(/MemberList), $Age_2020)
1 Like

Thank you very much, Mark! One question remains: where do I do the $MyList calculation? Probably not in the text… Would I best put it into the report note and make the calculation via quickstep? Or is there a more “Tinderbox Way” of doing it?

For a project of moderate size, I’d make it a rule on the note you’re exporting. That will do unnecessary work, but your computer won’t mind.

If you only want to do the work when you export, ^action() is what you want:

^action(
$MyList=collect(children(/MemberList), $Age_2020);
$MyNumber=avg(children(/MemberList), $Age_2020)
)
The age of the members is between 
^value($MyList.min) and ^value($MyList.max)

Note that you could test thing separately by first saving simple dummy data in $MyList and $MyNumber, and when that’s right, adding the rule or action to replace it with real data.

1 Like

Thanks again! Much appreciated.
There is one small problem blocking my progress, namely that in the note that I write for the analysis there is now an error popping up, stating that “This note’s $OnAdd cannot be parsed” - and then gives the code snippet you wrote.
I probably copied it and pasted it into the inspector to work on it, but I cannot detect it anymore - and have no idea how to get rid of it (screenshot attached)…Bildschirmfoto 2021-03-17 um 23.05.52

Click on the item in the pop-up. If the source problem is resolved the lest and the yellow icon with clear.

Now it has mysteriously disappeared. Turns out I clicked the error sign, NOT the text that was in the dialogue box (which I think should be more appropriately named monologue boxes, but that’s just me being tired…).

During the current session, I’m not sure what events clear error list items. Fixing a $Rule should self-clear rapidly, as the rule is called constantly by the app. $OnAdd gets called less often.

The ‘manual’ method to clear items in the pop-up listing is to double-click an item. I believe this forces a re-test and the item is cleared if fixed. If the pop-up’s list has only one item, when that clears the yellow warning icon also disappears.

I believe the method described here is correct.

BTW, have you tried using inline export code in the body of your $Text? I find this extremely useful. You an pull a single attribute from a single note, multiple attributes, our even a note and its children an descendants. The simplest example is single attribute.

Let’s say you wanted to pull $URL from Note A into Note be. In Note B’s text you’d put ^value($URL(“Note A”)^. That’s it, now you’ll get the $URL from Note A. REMEMBER: You must use straight quotes. To do this easily either set “$SmartQuotes” to false, or go to Edit>Substitutions>SmartQutoes, which will temporarily disable Smart quotes.

Thanks for the hint - and yes, that’s what I do, having learned it from watching your videos!

1 Like