jeudi 19 novembre 2020

Filter data using IF Statement in Tableau

I have a data source in tableau that looks something similar to this:

   SKU      Backup_Storage
  
   A        5
   A        1
   B        2
   B        3
   C        1
   D        0

I'd like to create a calculated field in tableau that performs a SUM calculation IF the SKU column contains the string 'A' or 'D' , and to perform an AVERAGE calculation if the SKU column contains the letters 'C' or 'B'

This is what I am doing:

IF CONTAINS(ATTR([SKU]),'A') or 
CONTAINS(ATTR([SKU]),'D') 
THEN SUM([Backup_Storage]) 
ELSEIF CONTAINS(ATTR([SKU]),'B') or 
CONTAINS(ATTR([SKU]),'C') 
THEN AVG([Backup_Storage])
END

The calculation above shows as valid, however, I see NULLS in my data source table. Any suggestion is appreciated.

I have named the calculated field: SKU_FILTER_CALCULATION

enter image description here

Aucun commentaire:

Enregistrer un commentaire