dimanche 22 novembre 2020

Sum two calculated fields Tableau

I have a dataset where I wish to place the data in two groups, based on the value name. I then wish to average the result for one group and sum the result for the other. Finally, I wish to sum these two to create a barchart.

Here is the data

Id  Total   Avail   group   Used
A   10      5   Group1      5
A   40      20  Group1      20
B   20      10  Group2      10
B   10      5   Group2      5
B   10      5   Group2      5
A   20      10  Group1      10
A   20      10  Group1      10
B   10      5   Group2      5
B   10      5   Group2      5

This is what I have done

1. First create calc. field named : group - group the data into groups

IF [Id] = 'A' THEN 'Group1'
ELSEIF [Id] = 'B' THEN 'Group2'
ELSE 'none'
END

    Then sum of Group1 (A) columns and take average of Group2 (B)

    CASE [group]
    WHEN 'Group1' THEN { FIXED [Id]: SUM([Avail])}
    WHEN 'Group1' THEN {FIXED [Id]: SUM([used])}
    WHEN 'Group1' THEN {FIXED [Id]: SUM([Total])}
    WHEN 'Group2' THEN { FIXED [Id]: AVG([Avail])}
    WHEN 'Group2' THEN {FIXED [Id]: AVG([used])}
    WHEN 'Group2' THEN {FIXED [Id]: AVG([Total])}
    END
    

    Here is that result:

    enter image description here

    Desired result:

    I wish to add the Group1(sum) and the Group2(avg) for the Avail, Used and Total so that the final chart combines the two blue values and combines the green values.

    The SUM of Group1A Avail = 45 and the AVERAGE of G Avail Group2 = 6
    So I wish the Avail section (blue) of the barchart to be: 51
    
    
    and the Used (green) should be 51 as well
    with the total as 102 (Ill add to tooltip)
    

    Any suggestion is appreciated- I am still researching this and any suggestion is appreciated

    Aucun commentaire:

    Enregistrer un commentaire