Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Cloud Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Cloud.
SOLVED

Is there a way to combine distinct count and rolling sum functions

Hi everyone, I have a sales data of item type and week number, i would like to see how many unique items I have sold to this date by week. Is there a way to combine distinct count and rolling sum functions?

2 REPLIES 2
Trifacta_Alumni
Alteryx Alumni (Retired)

Hi @Talha Ardic?,

 

You can nest the following three functions to return a rolling distinct count:

  1. ROLLINGLIST()
  2. ARRAYUNIQUE()
  3. ARRAYLEN()

 

Here is the single formula to enter as part of your step (note that the column called "region" is my example column name):

ARRAYLEN(ARRAYUNIQUE(ROLLINGLIST(region)))

The innermost function, ROLLINGLIST, returns an array of all string values in your column, given a set number of rows before and after the current row. This function does not respect unique strings, as you can see from the screenshot below:

If you look at row four, you can see that our array contains duplicate values for "southwest", because this string appears in both row three and row four.

 

To deduplicate the array created by ROLLINGLIST, you will nest the ROLLINGLIST function inside the ARRAYUNIQUE function. ARRAYUNIQUE retains only unique values in your list. You can see how ARRAYUNIQUE impacts the array created by the ROLLINGLIST function in the screenshot below:

You can see that row 3 and row 4 both contain the same list of values, without any duplication.

 

Finally, since you are looking for a distinct count, you will wrap the ARRAYUNIQUE function in the ARRAYLEN function. The ARRAYLEN function counts the number of items in your list and returns an integer. Since we deduplicated your list using the ARRAYUNIQUE function, this will output a distinct count. Here's how the final three-function formula looks when applied to my sample data:

 

Let me know if this helps! If it does, please mark the answer as "Best answer" so that other users know that your question has been resolved.

This helped, thank you so much!