Hi, some help with the following problem would be super
I have a multitude of rows, each one with 36 columns (one per month, for three years). Each one of them start with a 0 in the first column and then eventually have a non-zero in different columns (some in March, others in September, etc). I need to count the consecutive number of columns (i.e. months) that each row stays at zero
Hey Rahul, This is very achievable - I've written out an approach below but happy to mock it up for you later if you need.
- put a unique row ID on each row if you don't already have one using the record ID tool - use the transpose tool to flip from columns to rows, except for the record ID - then use a multi-row formula, groping by the record ID and setting the treatment of missing rows to null not zero. The multi row formula would be something like If isnull (row-1:value) and value=0 Then 1 Else if value !=0 then 0 Else row-q:value+1 Endif
Few more options for you Rahul (so that you can see how in Alteryx there are often multiple ways to solve the same problem.
Note: While I was testing this, I found an edge case had not yet been built into James's model, which is where every month is zero. It's not that James's solution is wrong at all, but just to be safe you can add a join back to the entites list (I've done this below in the solution using the Tile mode)
so - two different approaches to solve this (when you add in James's solution above - you now have 3 ways to tackle)
Using a multi-row formula:
Using @jdunkerley79's method of taking a minimum of the non-zero dates - but I've done it here using a Tile tool (which is suprisingly good for generating IDs)
Test DAta Generation: Oh- and along the way I had to generate some test data to test this - so built a quick random-test-data generator for this use-case.