What I have:
I have a csv of 4 values containing all possible permutations of x items (for this example say 4 different strings) with repetition (dt_1). I have a different csv containing some permutations (dt_2).
What I want to do:
I want to check if a row from dt_1 is present in dt_2, irregardless of the order of items… but can’t figure out a way to do this, so far my searches in the forum has left me none the wiser.
Example, row from dt_1 that contains the 257 possible permutations of apples, oranges, banans and grapes:
apple, apple, banana, orange
In dt_2 there is no row with this exact order, but there is the following row:
apple, banana, apple, orange.
I want to say that these two rows match, and copy the rows from dt_1 not present in any permutation in dt_2 to a new datatable.
Help?
(my first post here after a long time lurking and learning, allow me to use this occasion to thank all the great contributors in here for amazing work - I have learned a lot searching around in here!)
Try this solution. This is just a pseudo code. You need to use proper syntax of either vb.net or uipath activities.
MatchesVariable = “False”
For each row1 in dt1
{
save row1.itemArray in dt1Array
sort dt1Array
For each row2 in dt2
{
save row2.itemArray in dt2Array
sort dt2Array
if(dt1Array Equals dt2Array)
{
MatchesVariable = “True”
break
}
}
if(MatchesVariable = “False”)
{
append dt1Array as new row in new data table
}
}
Thank you both for your quick responses! I think I might need a bit more help to reach my goal. Which, I’m afraid, might seem a bit frivolous… All the same, a great learning experience for me!
@ppr attached you will find the two csv’s. As you can see the permutations are of four elements, while the “tried” permutations contain a far higher number of elements. The plan is to see if there are any untried permutations while adding one element after another to the “all possible permutations” cvs (permutations.csv). The first attempts will likely provide no untried combinations.
@Surya_Narayana_Korivipadu, I follow your logic - I think. But it might proove rather tasking considering the size of the possible permutations, or…?
(note: c̵s̵v̵ ̵f̵o̵r̵m̵a̵t̵ ̵w̵a̵s̵n̵’̵t̵ ̵a̵l̵l̵o̵w̵e̵d̵ ̵f̵o̵r̵ ̵u̵p̵l̵o̵a̵d̵,̵ ̵I̵ ̵h̵a̵v̵e̵ ̵u̵p̵l̵o̵a̵d̵e̵d̵ ̵x̵l̵s̵x̵ ̵v̵e̵r̵s̵i̵o̵n̵ ̵i̵n̵s̵t̵e̵a̵d̵. I’m a too new user to be able to upload files it seems. Can I PM them or something?)
rename csv file to txt on the extension part
OR
use just a little smple set but complete within the datastructure and create the markdown code, usable here within the post with the help of online tool link below: CSV To Markdown Converter
@lindanger
working with following sample data we get the result:
dt1,dt2 is simulating in general your case
ABCD is matching in dt2 DCBA
ABAB is matching in dt2 BBAA
AXYZ doesn’t have a match in dt2 - so we get it within the result
dt2 cols C1, C6 are simulating other columns which we do not need for the check
Variables:
Flow:
Assumption data from csv is read into a datatable with read csv activity
Line2 - create an ordered array from the looped dt1 row
Line3 - search for any row in dt2 which ordered 4 cols are equal to arrCheck from line 2
Line3 where - let pass dt1 the filter if there was no match in dt2
Line4 - add all passed dt1 rows to a List
Check defensive if there is an empty result and create or clone the dtResult