1
votes

I have a measure in my tableau data called "time". I'd like to create a calculated field using R. I have RServe successfully installed and I do this:

SCRIPT_REAL('hour(.arg1) + minute(.arg1)/60 + second(.arg1)/3600 ', [time])

but I get the error in the tableau calculated field:

ERROR: all fields must be aggregate or constant when using table calculation functions or fields from multiple sources.

ANy idea what I am doing wrong? Thank you.

1

1 Answers

0
votes

Tableau sends a query to the data source and receives a result set in return. The query results are aggregated, i.e. as from a SQL GROUP BY query. So each measure returned from the query is calculated from an expression involving SQL aggregate functions like MIN(), MAX(), SUM(), AVG(), COUNT() etc

Tableau then evaluates any table calculations upon the aggregated results. SCRIPT_REAL is a table calculation, as are things like WINDOW_AVG() etc.

So all the fields referenced in arguments to SCRIPT_REAL() must be either aggregate results or constants as the error message states. So passing MIN([time]) or AVG([time]) would be legal, but not just [time].

Whether those aggregate functions make sense may depend on what dimensions are in play on the worksheet -- as that determines how the data rows are partitioned.