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

Do you know if it's possible to replace NAs in one column with the average of the category it belongs to in another column?

ccarreras
7 - Meteor
 
1 REPLY 1
Trifacta_Alumni
Alteryx Alumni (Retired)

Hey Riley,

 

First, you'll want to create a column that displays the average value grouped by category. The following step should accomplish this:

Transformation: Derive

Formula: AVERAGE(value_column)

Group by: category_column

New column name: average_column

 

Next, you'll want to replace your NAs in the column I'll refer to as your_column. To do this, you'll want to set the NA values in your_column to the values in average_column, and leave the other values as is. Since it's unclear as to whether your NA values are labeled as 'NA' or if they are missing values, I'll list ways to deal with both. If they are labeled 'NA':

Transformation: Set

Columns: your_column

Formula: IF(your_column == 'NA', average_column, your_column)

 

If they are missing values:

Transformation: Set

Columns: your_column

Formula: IFMISSING(your_column, average_column)

 

In wrangle, the above three steps look like this:

  • derive value: average(value_column) group: category_column as: average_column
  • set col: your_column value: IF(your_column == 'NA', average_column, your_column)
  • set col: your_column value: IFMISSING(your_column, average_column)