jumpman8947
jumpman8947

Reputation: 581

Python Script calculation for list data type returned in Tableau

I have a script in python as follows

Script_INT("
  testing = _arg1 - _arg2
return test ",
SUM([scores]), SUM([students])
)

This gives me an error of

TypeError: unsupported operand type(s) for -: 'list and 'list' "

When i modify the script to just return 'scores' it prints a number for example 20. and when i edit the script to return 'students' it prints a number for example 10. But when i try to subtract both fields in the script it is not allowing me even though they are coming out as numbers when return individually no calculations.

How can i subtract the two fields to get it to return a number?

Upvotes: 0

Views: 562

Answers (1)

PSK
PSK

Reputation: 367

_arg1 and _arg2 are lists so you cannot subtract them. Check the number of values in your lists with print(len(_arg1)) and print(len(_arg2)). If you expect them to have only one value each testing = _arg1[0] - _arg2[0] should work.

Upvotes: 0

Related Questions