operation with many numeric columns without unpivoting

Hi everyone,
I have a dataset with multiple monthly revenue columns (e.g., Jan-2023, Feb-2023, …,Dec-2040) . I need to check whether the revenue for each month is higher, lower, or the same compared to the prior month (e.g., Jan-2023 vs. Feb-2023, etc).

Since my dataset is already long format and has many columns, I would like to use a loop (a Column List Loop?). However, I’m not sure how to access the previous iteration’s column (i.e., the column from the prior month) within the loop.

Does anyone have an idea on how I can accomplish this without unpivoting the data?

Thanks in advance!

Hi @Homa

See this wf Column_Index_Test.knwf (111.1 KB) . It uses a Window loop (stepsize = 2) to compare 2 columns at the time. In order to filter the relevant columns you need some help of flow-variables.
One thing you have to do yourself is configuring the Column Comporater node.
See if this works for you.

afbeelding

gr. Hans

3 Likes

Brilliant—thanks a lot! It works fantastically.

I just have a small issue with the Column Compare node. I need to handle different cases, such as when Column 1 < Column 2. In this scenario, I also need to check whether Column 1 = 0, which indicates that there were no sales in the prior month and now we have a new customer, and so on.

It would be awesome if there were a way to insert both flow variables into a node like the Column Expression node, where I could write a more complex nested if expression. Any idea on that?

if they are ordered, you can always access them using the index (or default name by removing the column name temp.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.