row comparison

Hi @Abhiram

Glad to hear that you’re making progress. Are you able to give an example as I don’t understand what you meant by it passing only one condition.

1 Like

Sure,

Actually i tried in the original spread sheet where

Business Date Legal Entity ETID Cash Location Currency Amount Transaction Sub Type Activity Is Contra Cleared?(Yes/No)
2021-06-01 002 XYZ EXO Dollar 5671 BUY SETT No
2021-06-02 0CG AB XA9 euro 2598 SELL PART Y Yes
2021-06-02 0CG AB XA9 euro 2598 SELL REIN Y Yes
![image 690x80](upload://LGWHHXp9YzOd0w3SjT3QL19RfC.png)

our conditions was if Activity = PART and Activity = REIN and ETID = ETID,CASH LOcation = CASH Location, Currency = currency but in the data where if sometimes is contra flag = ‘Y’ then out put need to be as NO but i am getting out put as Yes

While i testing i found this , may be we need to modify some thing in Rule engine node

Ok, so this will be because in the conditions for REIN / PART (condition 3 in the spreadsheet), I noted "Is Contra = any, because in your rules there wasn’t any mention of it except when you said it must be “Y” for specific conditions (and I have no idea what “Is Contra” means) :joy:

So, to resolve that, you will probably need to look at the Rule Engine, and find where I commented it as “Condition 3:”

and then include additional clauses to ensure that Is Contra=“N” in order for the value to be set to “Yes”
i.e.

// condition 3:
$Activity$="PART" AND $Activity(Previous)$="REIN" AND $Cash Location$=$Cash Location(Previous)$  AND $Is Contra$="N" AND $Is Contra(Previous)$ ="N" =>"Yes"
$Activity$="REIN" AND $Activity(Previous)$="PART" AND $Cash Location$=$Cash Location(Previous)$  AND $Is Contra$="N" AND $Is Contra(Previous)$ ="N" =>"Yes"
$Activity$="PART" AND $Activity(Next)$="REIN" AND $Cash Location$=$Cash Location(Next)$  AND $Is Contra$="N" AND $Is Contra(Next)$ ="N" =>"Yes"
$Activity$="REIN" AND $Activity(Next)$="PART" AND $Cash Location$=$Cash Location(Next)$  AND $Is Contra$="N" AND $Is Contra(Next)$ ="N" =>"Yes"

You should also review the table in my previous post (the one containing the workflow) and if Is Contra="N" is important to those other conditions too, then you should make the appropriate changes in the rule engine for these too.

Hi @takbb

i think is there any way should we give " != (not equal) "

because you are suggesting that Is Contra = N instaed of that Is Contra ! = Y it will work i guess

Hi @takbb

it’s working thanks a lot

1 Like

Hi @takbb ,

small doubt it’s working fine but is there condition shall we put that all the conditions need to passed that definitley need to compare with 2 rows .

i mean if already 2 rows got output “YES”

but our conditions again it is taking and comparing with already row got “YES”

Hi @Abhiram

Yes you can do this, but I agree the syntax is not immediately obvious.

If you want to say $x$ != "Y" you actually write it as NOT $x$ = "Y"

so for example

$Activity$="PART" AND $Activity(Previous)$="REIN" AND $Cash Location$=$Cash Location(Previous)$ AND (NOT $Is Contra$="Y") AND (NOT $Is Contra(Previous)$ ="Y" ) =>"Yes"

I’ve put the NOT clauses in parentheses as I like to keep them self- contained and it makes the intent explicit.

1 Like

Just to check my understanding, are you saying that you might have a situation where 3 adjacent rows all match one or more conditions in which case you’d only want the first two to match and the third row should not now be compared with the second row, because that has already been matched with the first row?

Hi @takbb ,

Yes Takbb

1 Like

Hi @Abhiram , that came as a bit more of a challenge! :wink:

This had me scratching my head and I couldn’t see any easy way of doing this using the standard (non-scripting) nodes.

What I came up with was that having determined whether there was a match to previous or next row, a subsequent processor would have to go down the list of matches and decide which were now allowed, and which weren’t. To perform this process, I had to use a java snippet. There is a feature of the java snippet that allows us to retain some “state” between rows, so we can base actions on what we did during the processing of the row immediately prior to the current row. For further info and examples on that specific feature see the following post

But for that to work, I had to now have two Rule Engines, one for deciding if there was a match to previous row, and the other separately deciding if there was a match to next row. It also meant that the Rule Based Row Filter had to be removed, as the Java Snippet needed to work on the whole data set, and not just on the subset of rows if it were to work properly.

So the Rule Based Row Filter had to be removed, and the rules from there added (with slight modification) to each of the two new Rule Engines.

The upside was that a re-joining of the data set was no longer required.

I discovered a bug that made no difference previously, in the two joiners used for “lagging” the rows. The join columns were round the wrong way so the “previous” row columns were wrongly named (next) and the “next” row columns were being named (previous). This didn’t matter before, but it was wrong and would be very confusing with the two rule engines and the new java snippet referring to “next” and “previous”…

So unfortunately that small additional feature caused quite a dramatic change to the workflow design. It has to be said that row-comparisons isn’t KNIMES strongest point, and I would argue that it is quite common to want to compare rows, especially prior and next rows. It would be nice to have some kind of multi-row Rule Engine, some way of supporting such use cases.

Anyway, here is a new version of the workflow. It would be nice if it were to just “slot in” in place of the previous one, but I suspect you’ll either have to edit it, or else use a column renamer node to rename your input columns to match this workflow, and then rename them back again at the other end… :wink:

Set value on lagged row multi-column-conditions with adjacent rows (b).knwf (42.9 KB)

As before, this needs testing again if you are going to make use of it for real work! Hope that helps.

1 Like

hi @takbb,

thanks it got executed

1 Like

small help needed @takbb,

Actually, i want to copy the values in columns: a) Business Date
b)Feed ID
c)Record ID
d)LE code
e)ETID
f)Exception Discription

from WORK_EXAMPLE (Excel file) and need to paste that values into sheet name : Tracker in
Common_file.xlsx (9.5 KB)
COMMON_ file(excel file)

work_example.xlsx (9.6 KB)
where if COMMON_example excel file inside the sheet of Tracker has some formulaes also.

–>task need to copy and paste the data from columns in one excel file to another excel file without changing the format .

→ exactly it needs to append to that file(coomon _file)

And also if a excel sheet has column containing some mails,

how can i add those to in send mail node in knime

mail.xlsx (9.3 KB)

please can anyone try to help me?

Hi @Abhiram , I’ll take a look at your posts when I get a chance but I’m unfortunately busy with work at the moment so hopefully somebody else might be able to assist.

For your additional question about sending emails, as that is really a new question, you’d be more likely to get responses if you ask that directly as a new topic on the forum as it is a different subject.

With it buried under “row comparison” people who know more about sending emails might not come looking at it here. By all means refer back to this post for context.

I know we said before about not duplicating the question but in this case it’s actually a new question, so best to ask it as a new topic. Hope that makes sense :wink:

3 Likes

Hi Takbb,

can you help me on this ?

For mails topic i had done that

Hi @takbb,

Firstly thanks for the help which you previously given the solution for comparision task,

Right now my team had given some extra conditions for the same task total 8 conditions.

i had just added those extra conditions but it is not working properly,

Set value on lagged row multi-column-conditions with adjacent rows.knwf (41.9 KB)

in the above knime workflow i had used all the conditions, plz help me on this.

i am facing the error in

where i highlighted the part those rows need to value of No because as i am having the condition was IF ETID = ETID(Previous) && CASH LOCATION != CASH LOCATION && CURRENCY == CURRENCY && AMOUNT == AMOUNT && ACTIVITY = ACTV , ACTIVITY =CXLD

i had attached the knimw workflow with all 8 conditions in rule engine.

As i understand you are all busy with your own works, Apologies please consider my request and help me :slight_smile:

Hi @Abhiram -

I took a look here, but need more clarity about what you’re trying to do. There is some ambiguity in your statement above - for example CASH LOCATION != CASH LOCATION can’t be right, you must have meant to include a previous or next in there. Same for some of the other columns.

Maybe it would look something like this? It’s hard to tell based on what you’ve you described.

// condition 9:
($ETID$ = $ETID(Previous)$) AND (NOT $Cash Location$ = $Cash Location(Previous)$) AND (NOT $Currency$ = $Currency(Previous)$) AND (NOT $Amount$ = $Amount(Previous)$) AND ($Activity$ IN ("ACTV","CXLD")) => "No"
2 Likes