Imagine I have a table 2x2 in Google Sheets:
variable_1 | variable_2 |
---|---|
x | 10 |
y | 13 |
x | 7 |
z | 11 |
A Dynamic Table with with variable_1 in the lines and the sum(variable_2) as a value, i would getthe following table:
variable_1 | sum(variable_2) |
---|---|
x | 17 |
y | 13 |
z | 11 |
Now imagine that the first column is a qualitative variable with the following possible outcomes: x, y, z or w. Is there a way to, when I make a Dynamic Table, to display the "w" outcome with the value 0?
In R, i would define variable_1 as a factor and, automaticaly, the grouping would include the "w". I need to get the following table:
variable_1 | sum(variable_2) |
---|---|
x | 17 |
y | 13 |
z | 11 |
w | 0 |
CodePudding user response:
try:
=INDEX(IF(D2:D="",,IFNA(VLOOKUP(D2:D, QUERY(A1:B,
"select A,sum(B) group by A label sum(B)''"), 2, 0), 0)))