Sum based on two criteria

taylor
edited June 12 in Flows

I am looking for some help/advice on the best way to sum certain data within a list. I have a list of objects, and I want to sum the Receipts based on if the Month and Product matches. I've tried a couple different If statement variations, but I'm not getting what I need. The information used in the flow are coming from 2 separate databases, so I am unable to write a query to obtain this information easily.

Comments

  • Kathryn_Decisions
    edited July 31

    Start by using a Create Data step to make a list to hold all the sums of the matches. I have made a list of my ExampleDataStructure called FinalList. Then I pass List1 of my ExampleDataStructure into the first for EachStep and and pass List2 into the second ForEach step.

    Be sure to change the outputs of at least one of the ForEach steps so that you can access both items from the ForEach steps in the rest of the steps.

    In the Rule Collection Filter step, I have built an array containing both of the items I would like to compare in the rule.

    And in the rule, I compare both the months and the product.

    In the [Rule] Is Match, I pass in the matches from the Rule Collection Filter step and check if the List is Not Empty. If there isn't a match, the flow will move on to the next items to compare.

    If there is a match, I send the both items to an Add step to add the prices together.

    Then in another Create Data step, create a new ExampleDataStructure and pass in the month and product from one of the list items and the Total Price computed in the Add step.

    Lastly, we will add the new match to our Final List. It is important that the Original List and the New List have the same name!

Sign In or Register to comment.