Hi guys, I want to migrate Alteryx workflow into KNIME workflow. There is a multi-row formula node in Alteryx like this.
It simply gives values to column(Group ID) according to the values in column (2). If column(2) contains “com”, the values in column(Group ID) +1, else the values in column(Group ID) = value in the last row. The output should look like this.
Can anyone help me solve this problem? Thanks!
Your more likely to get help if you share some sample data. The Column Expressions node may work, but its hard to tell without some data.
The sample data is just like column(2) in the above picture.
Hi @ThomasChen , what I think @rfeigel meant was that if you can upload the sample data as text it makes it much quicker to help. Otherwise he or somebody else has to type in the data which is laborious and time consuming.
You can upload a file (eg csv) or you can write it as a table directly in the post. If you don’t know how to write it in a post as a table, I have a component which can help with that…
Hey there,
agree with @takbb and @rfeigel - makes life way easier…
That said I am in an exceptionally good mood this morning so here is one approach.
I don’t think there’s yet an as elegant way as in Alteryx as when using Multirow access e.g. in column expressions you cannot access the values of previous rows of the column you are currently creating.
There are some “hacky” ways I think that involve some Java Script that @takbb I think worked out - however if you want to go the low code way this can work:
- Filter for contains .com
- To the filtered table, add a running number ( I use rowIndex() in column expressions
- Join the filtered data set back with the main data set incl. left unmatched
- now use Missing values first to fill missing values in the Group ID column with the “previous value” - now you have all Groups 1 and over sorted
- Add another missing value node and set anything else to 0…
Overview:
WF:
alteryixmultirow.knwf (82.4 KB)
Ah yes, thanks for the reminder @MartinDDDD … the java snippet can be coded in such a way that it can remember the previous value but…
It’s actually relatively straightforward with Column Expressions, once you know the principle. (see above post)
Granted, it’s still a bit “hacky”, lol.
Thanks for your reply, but there is something wrong with your answer. The problem is that when there are two identical values in the column(2), the join result will be wrong. For example, for these values in column(2)
0
1com
1
2
3
4
1com
123djs
adfdc
sdc
sdcsvcom
sadd
asffvf
the join result will be
? | 0 |
---|---|
1 | 1com |
2 | 1com |
? | 1 |
? | 2 |
? | 3 |
? | 4 |
1 | 1com |
2 | 1com |
? | 123djs |
? | adfdc |
? | sdc |
3 | sdcsvcom |
? | sadd |
? | asffvf |
Do you know how to solve this problem? |
This should not happen if you join the tables on RowID as they are the same in both tables. You don’t join on the content of column(2), but on the RowID (as per my example).
… and this is where it becomes incredibly helpful if you can actually share your workflow as well…
I see. Next time I will share my workflow. Your solution works. Thank you very much.
btw, and just for info, as this is already solved…
The “hacky” Column Expression would be this:
var prevGroupID
if(prevGroupID==null)prevGroupID=0 /* initialises prevGroupID only once ( first row only ) */
//-----------------------------------------------------------------------------
if(indexOf(column("2"),".com")== -1 )
{
prevGroupID
}
else
{
++prevGroupID /* add 1 to previous group if we have found .com */
}
Wow, you are in a really hacking mood today. There is a much simpler solution to this problem (if I understand it correctly).
The rules in the Rule Engine are as simple as
$2$ LIKE "*.com*" => 1
TRUE => 0
count com.knwf (75.3 KB)
Have a nice day,
nan
just love it how “there are so many ways leading to rome” in KNIME
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.