For each/filtering question from data table

datatable
activities

#1

Hello,

I have a data table that I need to take different actions off of. Below is a sample DT:

Col1 Col2
A var1
A var1
A var1
A var2
B var2

I need to complete 1.xaml for each unique value in Col1, then within that loop, complete 1.1.xaml for each unique value in Col2 (and count occurrences of this combination).

What I need to do per the sample data above:
Complete 1.xaml for ‘A’, then invoke 1.1.xaml for ‘var1’ and have a count of 3 (I need to use this variable value).
Complete 1.xaml for ‘A’, then invoke 1.1.xaml for ‘var2’ and have a count of 1.
Complete 1.xaml for ‘B’, then invoke 1.1.xaml for ‘var2’ and have a count of 1.

Any help is appreciated!


#2

First thing I would recommend is better naming for your xaml files, 1 and 1.1 aren’t very descriptive, and makes it much more difficult for others to understand what is going on.

What I would do in this situation would to be to iterate through each row in the data table. First you would create a dictionary to count the number of instances of col1 col2 values. The dictionary would look like:
Avar1: 3
Avar2: 1
Bvar2: 1
Next, you can iterate through another for each row activity (after, not nested) but this time, checking the values of the dictionary. After you complete an action, set the number value to 0, and check before e ach iteration to make sure you don’t double up. Hope this helps!


#3

Hi Jacob,

You’ll be glad to know that the xaml names are dummy just like the data. Those are not actual names of xamls.

Thanks for the suggested approach. How would I go about counting the variable instances to a dictionary? I understand I’d do it in a for each for the DT, but what’s the syntax for adding to the dictionary?

Thanks!


#4

You should be able to check to see if a dictionary contains a key, if not, you can use the add to dictionary activity, with the value of 1. If there already exists an entry in the dictionary, assign the value in the dictionary to itself +1.
Also I only mentioned the xaml names because it confused me when I was first reading your question. Hope I was able to help!


#5

Hi Jacob,

I’m wondering how you would count the number of instances of col1 and col2 values? I have attached a sample excel sheet and have two names for the columns to better understand the context of how you would do this task.

SampleDT.xlsx (9.5 KB)


#6

are you looking for each unique value or the pair? What would be the result of finding this information on your sample excel file?


#7

For each location I need to count the types (ie Chicago has 2 As, and 1 B). I need to take those quantities and order for Chicago 2 As and 1 B types. Then for LA I need to start a new order for that locaiton that will do the same so it will count that it needs to order 1 type A and 1 Type B for LA Location.