Best answer

Possible to do calculations on an array of line items?

  • 25 March 2020
  • 3 replies
  • 3406 views

Userlevel 1

Hey!

I am building a zap to integrate Shopify and Xero (putting invoices into xero).

I need to calculate discounts percentages, using the discounts per line item and their price.

This involved doing maths on each line item and then producing a new set of line items with the discount percentages.

When I do this maths, instead of calculating per line item it puts all of the value to together and produces a single number output.

 

Does anyone know if you can run maths on an array of line items?

Thanks, Harry.

icon

Best answer by Doyle 25 March 2020, 16:54

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Userlevel 2
Badge +2

Hi Harry! It looks like you’ve been able to work with a member of Zapier’s Support team to take a closer look at your Zap. Please let us know if you have any outstanding questions — we’re happy to help!

 

In general, it’s possible for the Formatter function “Spreadsheet Style Formula” to perform maths operations on line items.

 

For example, you might have two sets of line items:

Price: 64,200

Discount Amount: 6.4,30

 

And want to calculate the discount percentage of each individual line item. So you could use a spreadsheet formula like this: 

((Discount Amount / Price) *100)
 

 

In this example, the result is 10,15 — formatted as line items:

 

 

The biggest requirement for this kind of formula is for both the Price and Discount Amount fields to already be formatted as line items. If the input fields aren’t yet formatted as line items, then there are some other Formatter steps that can be helpful to use first, like Text to Line-Item, or Line Itemizer.

- Doyle 👍

Userlevel 1

Hi Doyle!

Sorry I stopped responding on the chat earlier, I dropped connection and when I came back it wouldn’t let me talk (or reopen a new chat).

I have been trying a few different things (including the above) but still can’t seem to get it working. Would you be able to have a quick look?

This is my setup

 

And this is what it tests and the error I get. Is the 500 error something to do with it?



Cheers, Harry.

Userlevel 1

Fixed it!

So my discount array had 3 null values at the end (which don’t show up in the test formula so I didn’t think would be an issue).

I’ve now made sure the arrays get sent through as 3 values and it’s now working.

Cheers!