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.
updated Here is the data
Id Total Avail Date group used
A 10 5 9/1/2020 Group1 5
A 40 20 9/1/2020 Group1 20
B 20 10 9/1/2020 Group2 10
B 10 5 9/1/2020 Group2 5
B 10 5 9/1/2020 Group2 5
A 20 10 9/1/2020 Group1 10
A 20 10 9/1/2020 Group1 10
B 10 5 9/1/2020 Group2 5
B 10 5 9/1/2020 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 create calc. field - sum_avg 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:
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
UPDATE
I have a dataset where I wish to reflect the totals from the custom SQL query. Here is some sample data:
Size Tb Val type Group Sum_AVG SKU Last_refreshed
270 90.5 Free_Space_TB Group2 90.5 Excel 9/1/2020
270 179.5 Used Group2 179.5 Excel 9/1/2020
Here is the custom query output
Here is my view
The avail and used appear when I hover over, but how would I include the total?
This is the calculation I am using (thanks to help from a SO member):
{SUM({Fixed [type]: ZN(sum(if [Group]= 'Group1' then [Val] end))})
+
sum({Fixed [type]: zn(avg(if [Group] = 'Group2' then [Val] end))})}
SUM_AVG is:
zn(sum(if [Group]= 'Group1' then [Val] end))
+
zn(avg(if [Group] = 'Group2' then [Val] end))
I am doing something wrong, because it is totaling up across all the columns, when I just want the total for each column.
(Used was created from using a custom query)








