How do I add an entry to bundles that is the sum of two values in each bundle?

I feel like I’m misunderstanding something very basic in make: I have a hundred bundles that are a collection of sales transactions. Each bundle has several ‘columns’ imported from a CSV, such as item name, net sales, quantity, etc.

I want to add a column to each bundle, let’s call it “Price” that is simply each bundle’s net sales divided by quantity.

For example, if one of my bundles had a quantity of 3 and a net sales of 18, I want to add a column that is “Price” with a value of 6.

Right now, I can only seem to find aggregators or iterators, but I can’t find a module that simply edits each bundle without either aggregating or iterating. Is there a module that handles this that I’m not seeing in documentation, or is this something handled in some other fundamental way?

@pswinch Make will process each of your bundles generated.

So if you want to calculate something like price per item. You just set the calculation/update to happen after the bundles get generated and the calculation module will run 100 time (or however many bundles are generated from your previous module)

Aggregator helps if you want to combine all the prices from the 100 lines of sale. You can set an aggregator that combines all the bundles to an array and you can sun the values of that array to get total sale cost (or whatever other data/calculation you are looking for)

Hope that helps

1 Like

Hello @timlittletech and thank you! What module would you use to make the calculation happen? I’m not sure how I go about setting it to actually happen.

Hello,

You didn’t supply a detailed example of your data, so I had to make something up.

If you start with something like this:
image

Is your goal to end up like this?
image

If so, you could accomplish this using an “Aggregate to JSON” followed by Parse JSON. What you do next depends on what you’re doing with the information.

Aggregate to JSON will go through each bundle (as in my first example screenshot), get the info you want from it, then create a new structured object from it. With this you’d also have to create your own data structure.
Parse JSON would then turn that JSON back into bundles (my second example screenshot).
After Parse JSON, you could use a Text Aggregator to make a new file, CSV module to make a new CSV, Array Aggregator to make one bundle with a bunch of arrays, etc…

I’ve attached a blueprint you can import into a new scenario to get a better idea of how it works.
calculate_prices.json (10.6 KB)

2 Likes

That is a very useful work around! Thank you! I parsed the data to JSON (which also allowed me to work with field names in my data structure rather than column numbers from the CSV), and could perform any needed calculations at the same time. Then parsed it.

I get the sense that Make wants you to perform calculations while doing other steps, but that didn’t seem possible when I needed to perform calculations to create new fields prior to other steps.

3 Likes

I like this method too because it saves so many Operations!
If you have a chance to check out Make Academy, they discuss this technique for a very similar situation.

3 Likes