You can use a variety of mathematical and statistical functions to calculate metrics within a column.
To calculate metrics across columns, you can use a generalized version of the following example.
Your dataset tracks swimmer performance across multiple heats in a race, and you would like to calculate best, worst, and average times in seconds across all three heats. Here's the data:
In the above data, Racer Y was disqualified (DQ) in Heat 2.
To compute the metrics, you must bundle the data into an array, break out the array into separate rows, and then calculate your metrics by grouping. Here are the steps:
When the data is imported, you may need to create a header for each row:
You can paste Wrangle steps into the Transform Builder.
- The columns containing heat time data may need to be retyped. From the drop-down next to each column name, select Decimal type.
DQvalue in the Heat2 column is invalid data for Decimal type. You can use the following transform to turn it into a missing value. For purposes of calculating averages, you may or may not want to turn invalid data into zeroes or blanks. In this case, replacing the data as
0.00causes improper calculations for the metrics.
replace col:Heat2 with:'' on:'DQ'
Use the following to gather all of the heat data into two columns:
You can now rename the two columns. Rename
You may want to delete the rows that have a missing value for
delete row: ISMISSING([value])
You can now perform calculations on this column. The following transforms calculate minimum, average (mean), and maximum times for each racer:
derive value:MIN(HeatTime) group:Racer as:'BestTime'
derive value:AVERAGE(HeatTime) group:Racer as:'AvgTime'
derive value:MAX(HeatTime) group:Racer as:'WorstTime'
To make the data look better, you might want to reformat the values in the
AvgTimecolumn to two decimal points:
set col:AvgTime value:NUMFORMAT(AvgTime, '##.00')
After you use the
move transform to re-organize your columns, the dataset should look like the following: