toReachThreshold
Counts the summed values required to reach a target threshold.
The first parameter takes a series of numbers, and the second takes a target threshold value. The function works through the series, summing the values until the total equals or exceeds the threshold. The result tells you how many values were summed.
The function works left to right through a list or table row. If the input is a table column, the function works top to bottom. Any null or empty values are ignored.
The function returns -1 when the sum total never reaches the threshold.
Parameters
NUMBER LIST (list, column, or row)
A list, column, or row of numbers.
TARGET (number)
The target threshold value.
Examples
The function works left to right through a list.
ATL in Script | Result |
---|---|
| 3 |
| 4 |
| -1 |
Note that when the threshold value is a negative number, exceeded = LESS THAN.
ATL in Script | Result |
---|---|
| 3 |
The function ignores null or empty values.
ATL in Script | Result |
---|---|
| 3 |
Using toReachThreshold with table data
Assume a "Describe the Table" project with this data:
Month | Sales | |
---|---|---|
Row 1 | January | 5,257.25 |
Row 2 | February | 12,565.98 |
Row 3 | March | 11,245.95 |
Row 4 | April | 10,670.23 |
Row 5 | May | 12,350.55 |
Row 6 | June | 8,978.19 |
The function can take a column variable. It works top to bottom through the column.
ATL in Script | Result |
---|---|
| 3 |
| 5 |
Here's how you might use toReachThreshold
to produce narrative text:
We reached our yearly sales target of $50K after [[numToWords(toReachThreshold(Sales, 50000))]] months.
The output text:
We reached our yearly sales target of $50K after five months.
Note
In a "Describe Row in Context" project, the column variable is SalesColumn
.