In my ongoing series of Expert Hacks/Tips (lol) I wanted to show how we use three simple formatter steps to "count" the number of line items in any situation. We can even use this same methodology to "count" the number of line items that match a specific value or condition.
Here's a video walk through with text explanation below.
Loom | Send a video. Not a thousand words.
Scenario:
So we're jumping in the middle of a zap where you already have a line item (say from a new invoice trigger in Quickbooks). And you want to count how many different products are on the invoice, or alternatively you want to count how many products of type=shoe are on the invoice.
To count type=shoe lines
Step 1: Formatter by Zapier: Utilities: Lookup table.
- Use the "Type" as the input
- Put "shoe" on the left of the lookup table and 1 on the right
- Leave the Fallback Value empty
Step 2: Formatter by Zapier: Utilities: Line Item to Text
- Use the output of the previous step
Step 3: Formatter by Zapier: Numbers: Spreadsheet-style formula
- Use the output_text of the previous step in the following formula
- sum({{step2_output}})
And now the output of Step 3 will be the total number of line items where type=shoe.
To count all lines
To count ALL line items it's the exact same three steps with only a change made to the lookup table. I hadn't ever thought of a use case for doing this with a lookup table until I was recording the above video and it dawned on me that both the fallback value AND the lookup table are optional. I had assumed only the fallback value was optional.
Step 1: Formatter by Zapier: Utilities: Lookup table.
- Use any variable from the line item as the input. (id, description, quantity etc.)
- Leave both the right and the left of the lookup table empty
- Put 1 in the Fallback Value
Step 2: Formatter by Zapier: Utilities: Line Item to Text
- Use the output of the previous step
Step 3: Formatter by Zapier: Numbers: Spreadsheet-style formula
- Use the output_text of the previous step in the following formula
- sum({{step2_output}})
And now the output of Step 3 will be the total number of line items.
As always, I'd love feedback on my methodology and if I'm missing something here or if this inspires you to develop cool new ways to use formatter. And is there anyway to do this with 1 or 2 steps instead of three?