Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Count # of occurance of field across columns

hal_dal
8 - Asteroid

Hi,

 

I have a specific condition that I'm struggling with and wondering if anyone is able to help.

 

I have a set of input data as below:

(I have a bunch of date in that Date field (repeating multiple times) and ID field that also repeats multiple times

 

Project IDDateStatus
:0002740811/7/2019 
:0002740811/14/2019 
:0002740811/21/2019 
:0002740811/28/2019 
:0002740812/5/2019Not Rated
:0002740812/12/2019Not Rated
:0002740812/19/2019Not Rated
:000274081/9/2020Not Rated
:0003527611/7/2019Not Rated
:0003527611/14/2019Not Rated
:0003527611/21/2019Not Rated
:0003527611/28/2019Not Rated
:0003527612/5/2019Not Rated
:0003527612/12/2019Not Rated
:0003527612/19/2019Not Rated
:000352761/9/2020Not Rated
:0003725311/7/2019Not Rated
:0003725311/14/2019Not Rated
:0003725311/21/2019Not Rated
:0003725311/28/2019Not Rated
:0003725312/5/2019Not Rated
:0003725312/12/2019Not Rated
:0003725312/19/2019Not Rated
:000372531/9/2020Not Rated
:0003726311/7/2019Not Rated
:0003726311/14/2019Not Rated
:0003726311/21/2019Not Rated
:0003726311/28/2019Not Rated
:0003726312/5/2019Not Rated
:0003726312/12/2019Not Rated
:0003726312/19/2019Not Rated
:000372631/9/2020Not Rated
:0003880411/7/2019Yellow
:0003880411/14/2019Yellow
:0003880411/21/2019 
:0003880411/28/2019Yellow
:0003880412/5/2019Yellow
:0003880412/12/2019Yellow
:0003880412/19/2019Yellow
:000388041/9/2020Yellow
:0003983611/7/2019 
:0003983611/14/2019Not Rated
:0003983611/21/2019Not Rated
:0003983611/28/2019Not Rated
:0003983612/5/2019Not Rated
:0003983612/12/2019Not Rated
:0003983612/19/2019Not Rated
:000398361/9/2020Not Rated



I initially had to use transpose to get the date field turn into their own columns and Status field as their records (which Im able to do successfully)

then i was asked to also count the number of occurance/frequency of the "Yellow" from that status field. (Only when there's Yellow in consetutive rows and no other values appear in between, if there is (like my example below, then it will start counting for Yellow again)

 

 

I need to also figure out how many times that Yellow was repeated for the particular ID in the particular date.

 

Below is the expected results:

 

Project IDW11/7/201911/14/201911/21/201911/28/201912/5/201912/12/201912/19/20191/9/2020
:000274080    Not RatedNot RatedNot RatedNot Rated
:000352760Not RatedNot RatedNot RatedNot RatedNot RatedNot RatedNot RatedNot Rated
:000372530Not RatedNot RatedNot RatedNot RatedNot RatedNot RatedNot RatedNot Rated
:000372630Not RatedNot RatedNot RatedNot RatedNot RatedNot RatedNot RatedNot Rated
:000388045YellowYellow YellowYellowYellowYellowYellow
:000398360 Not RatedNot RatedNot RatedNot RatedNot RatedNot RatedNot Rated

 

you will see in the example for ID 00038804 that Yellow counts as 5 rather than 7 because there was a blank (or could be any other values) in between it.

 

Please let me know if my explanation is confusing.

Thanks in advance!

21 REPLIES 21
hal_dal
8 - Asteroid

@AbhilashR 

Is it okay I dm you?

hal_dal
8 - Asteroid

hal_dal_0-1588717512666.png

 

hal_dal
8 - Asteroid

@AbhilashR 

I have posted my sample data here as well.

Maybe the data I have posted before works a bit differently?

AbhilashR
15 - Aurora
15 - Aurora

Hi @hal_dal, give this version a try. It is the same as previous, just that I sort my universe upfront to group all dates for a given ID, and then use the multi-row formula tool to compute the output. 

hal_dal
8 - Asteroid

Thank you so much! @AbhilashR 

Just one other thing though,

How would I  take into account where the later fields may not be Yellow?

 

and what I mean by that is:

 

hal_dal_0-1588731469847.png

 

 

example above, the count is still 0 because the last field is Green and not Yellow

AbhilashR
15 - Aurora
15 - Aurora

Sorry, I don't quite follow the logic for the row you highlighted in yellow. I would imagine the count would be 3 since I see three consecutive Yellows from the right. 

hal_dal
8 - Asteroid

@AbhilashR 

I would only count those "Yellows" where that row of Project ID absolute ends in Yellow and nothing else.

Basically,

 

I need to count the consecutive "Yellows" but that's only if there's no other available fields/blank before and after it. (when we look at it across the columns for that particular ID)

Sorry for the confusion, I have just been introduced to this concept and I'm confused myself as well.

AbhilashR
15 - Aurora
15 - Aurora

@hal_dal

No problem at all. Please feel comfortable asking as many questions as you need to get to your destination. I have modified my solution to accommodate for this new piece of information (assuming I am not confused). 

 

It assumes you need Yellow count for rows whose latest status value is Yellow, and not anything else. Below is a summary of only those rows that have Yellow count (the workflow will give you the entire Univ.)

AbhilashR_0-1588739546872.png

Take a look and let us know.

 

hal_dal
8 - Asteroid

@AbhilashR  thank you so much!

Do you have any suggestions of how I can handle a situation where

The first column has values but the last may not?

Where in my example, I had Yellow for the first column and the rest are all blank and the yelloe was still counted.

How can I fill in that gap for situations where those columns may not have any values (i.e. they were not passed in the first place from the input)

AbhilashR
15 - Aurora
15 - Aurora

In other words, if a particular ID has only one value coming in, you want to artificially introduce new dates to ensure every ID has the same number of dates (i.e. rows) in them? If yes, then you could explore using the Generate Rows tool. Identify Min and Max date of your universe, which basically gives you the lower and upper bounds in your data. Then use these in the Generate Row tool.

Labels