# Calculate percentage breakdown over field value for any combination of other settings

I have data in my dataset similar to the following:

``````Date  StockCount Color Size Model
01/01     3     Red    L    A
01/01     0     Blue   L    A
01/01     0     Red    M    A
01/01     2     Blue   M    A
01/01     1     Red    S    A
01/01     5     Blue   S    A
01/01     4     Red    L    B
01/01     1     Blue   L    B
01/01     6     Red    M    B
01/01     1     Blue   M    B
01/01     2     Red    S    B
01/01     4     Blue   S    B
01/02     1     Red    L    A
01/02     7     Blue   L    A
01/02     6     Red    M    A
01/02     0     Blue   M    A
01/02     0     Red    S    A
01/02     2     Blue   S    A
01/02     4     Red    L    B
01/02     5     Blue   L    B
01/02     1     Red    M    B
01/02     7     Blue   M    B
01/02     2     Red    S    B
01/02     2     Blue   S    B
``````

I’m graphing stock counts over time to show the rise and fall of levels over time. It is a simple line grpah with controls allowing you to select Size and Model- either a specific value, or just Select all.
I’d like to calculate what percent of the widgets in stock are Red for the set combination of model andsize and produce a visual across the days showing how that percentage changes.

I’ve tried a calculated field
sumIf(StockCount,Color=‘Red’)/sum(StockCount)

but this just returns 0 for all days.

Thank you for your time and attention.

I haven’t tried this but I had a read of the syntax and it seems to me that SumOver() is what you need.
From the syntax page:

``````sumOver
(
sum({Billed Amount}),
[{Customer Region}]
)

So, your equivalent would be something like:

sumOver
(
sum({StockCount}),
[{Color}]
)

Essentially, as far as I can tell, it is partitioning the data by Color and will return the StockCount by Color.
Therefore, for any row you can just look at the value of the calculated field,
let's say you call it "Calc_StockByColor", and it will return the relevant value for that row.``````

Hi, @momnotmom42. Did @RichardAustin’s solution work for you? I am marking his reply as, “Solution,” but let us know if this is not resolved. Thanks for posting your questions on the QuickSight Community Q&A Forum!