Three Google Sheets' data graphs (pie charts) in one graph - google-sheets

I have three google sheets of data in one spreadsheet. these sheets containing the data of ABC Town students. ABC Town has 3 Streets called Street 1, Street 2 and Street 3.
Street 1 has 10 Students in different grades.
Street 2 has 6 Students in different grades.
Street 3 has 2 Students in different grades.
Every sheet has Students Grade summary Pie Graph. Now What I need is,
I have to combine these three pie charts into one chart to get a final summary of three sheets. how can I do this? Please.
This is my spreadsheet: https://docs.google.com/spreadsheets/d/1NmCSRPaoGCpuyfxv24z2-M8TNktBjHNt7BoaMF6LCJY/edit?usp=sharing
explained in image:

or maybe you just want to combine all 3 charts (?) like:
demo spreadsheet

if you map out your data the right way you can create pie chart with sub-slices for each of your three pie charts and then you will just layer them. here is an example:
your dataset of A1:C is not in "good" shape for creating a chart, so first, you will need to re-shape it by adding few formulas in auxiliary columns which you can hide when done
in cell E1 paste this formula and create a base pie chart. this will create even ratio between Libaries. select primary color for each libary and maximze chart style
={"Libaries"\""; {TRANSPOSE(SPLIT(REPT(1&" ";
COUNTA(UNIQUE(FILTER(B2:B; B2:B<>""))));" "))\
UNIQUE(FILTER(B2:B; B2:B<>""))}}
if you got #ERROR! paste this into E1 cell:
={"Libaries",""; {TRANSPOSE(SPLIT(REPT(1&" ",
COUNTA(UNIQUE(FILTER(B2:B, B2:B<>""))))," ")),
UNIQUE(FILTER(B2:B, B2:B<>""))}}
paste this formula in G1 cell to create labels:
=ARRAYFORMULA(SPLIT(JOIN("×";
TRANSPOSE(REPT(UNIQUE(FILTER(B2:B&"×"; B2:B<>"")); 2))); "×"))
then paste this formula in G2 to create dataset for 2nd chart:
=ARRAYFORMULA(QUERY(TO_TEXT($A$2:$C);
"select count(Col3), Col3
where Col1 is not null and Col2='"&G1&"'
group by Col3
label count(Col3)''"; 0))
after this you will need correction formula which can correct position of the first set of pie slices. paste this in G6 cell and create 2nd pie chart from range G2:H. then play with colors and set color of the correction pie on None
=IF(SUM(ARRAYFORMULA(QUERY(TO_TEXT($A$2:$C);
"select count(Col3)
where Col1 is not null and Col2='"&G1&"'
group by Col3
label count(Col3)''"; 0)))>3;
SUM(ARRAYFORMULA(QUERY(TO_TEXT($A$2:$C);
"select Col3, count(Col3)
where Col1 is not null and Col2='"&G1&"'
group by Col3
label count(Col3)''"; 0)))*2; 6)
when done, overlay 1st chart with 2nd chart
then paste this formula in i4 cell (this will be dataset for 3rd chart)
=ARRAYFORMULA(QUERY(TO_TEXT($A$2:$C);
"select count(Col3), Col3
where Col1 is not null and Col2='"&I1&"'
group by Col3
label count(Col3)''"; 0))
next you need correction again. this time twice. paste this formula in i2 and i7
=SUM(ARRAYFORMULA(QUERY(TO_TEXT($A$2:$C),
"select Col3, count(Col3)
where Col1 is not null and Col2='"&I1&"'
group by Col3
label count(Col3)''", 0)))
now you can construct 3rd pie chart from range i2:J. again play with colors and hide correction slices. when done overlay it on top of 1st and 2nd chart
when done paste this formula in K4 cell (this will be dataset for the 4th pie chart)
=ARRAYFORMULA(QUERY(TO_TEXT($A$2:$C);
"select count(Col3), Col3
where Col1 is not null and Col2='"&K1&"'
group by Col3
label count(Col3)''"; 0))
and again you need to correct the position with this formula pasted in K2 cell
=IF(SUM(ARRAYFORMULA(QUERY(TO_TEXT($A$2:$C);
"select count(Col3)
where Col1 is not null and Col2='"&K1&"'
group by Col3
label count(Col3)''"; 0)))>3;
SUM(ARRAYFORMULA(QUERY(TO_TEXT($A$2:$C);
"select Col3, count(Col3)
where Col1 is not null and Col2='"&K1&"'
group by Col3
label count(Col3)''"; 0)))*2; 6)
create 4th pie chart from range K2:L, play with colors, hide correction slice, possition it on all previous charts
if you want to put up some labels then you can insert drawings and overlay it once again
demo spreadsheet

Related

Multi-level nested pie chart in google sheets

I need a multi-level nested pie chart in google sheets.
To show number sums in categories and sub-categories. Can use code or just formulas.
Or if a system similar to google sheets already has a easy configurable nested pie-chart I can consider using it.
Here is a sample sheet with 2 charts I want to combine:
https://docs.google.com/spreadsheets/d/1TvOf_tRNFS4zqbYR8EMGfTH1krI_iX9resrQ_AwmGZ8/edit?usp=sharing
It can be similar to the one here, but with sums instead of counts:
Three Google Sheets' data graphs (pie charts) in one graph
Or a D3 Sunburst Partition.
dynamic fx:
=ARRAYFORMULA({TRANSPOSE(QUERY({A1:C}, "select sum(Col3),Col1 where Col1 is not null group by Col1 label sum(Col3)'Base Pie'"));
{"♀", IFERROR(1/(1/TRANSPOSE(MMULT(TRANSPOSE(IF(SEQUENCE(COUNTUNIQUE(A2:A))<SEQUENCE(1, COUNTUNIQUE(A2:A)),
QUERY({A2:C}, "select sum(Col3) where Col1 is not null group by Col1 label sum(Col3)''"), )*1), SEQUENCE(COUNTUNIQUE(A2:A), 1, 1, )))));
QUERY(QUERY({A2:C, ROW(A2:A)}, "select Col2,max(Col3) where Col3 is not null group by Col4,Col2 pivot Col1"), "offset 1", )};
{"♂", IFERROR(1/(1/TRANSPOSE(MMULT(TRANSPOSE(IF(SEQUENCE(COUNTUNIQUE(A2:A))>SEQUENCE(1, COUNTUNIQUE(A2:A)),
QUERY({A2:C}, "select sum(Col3) where Col1 is not null group by Col1 label sum(Col3)''"), )*1), SEQUENCE(COUNTUNIQUE(A2:A), 1, 1, )))))}})
the formula takes data in A:C range and creates all necessary steps, columns and rows that will feed pie charts.
rows labeled ♀♂ serve as pie chart ratio correctors
column E can be used as a subcategory labeling system if needed
in the same manner row 3 can be used as labels for base pie
first, we create a base pie chart (from the black row) which will serve as background:
next, for each colored column we create a separate pie chart that we overlay on top of the base pie chart. note that colors and sub-colors needs to be selected manually for each slice by double-clicking a given slice and selecting either color or none in the case of ♀♂ slices
and repeat for the next column...
demo spreadsheet
E2:
=QUERY({A2:C}, "select Col1,sum(Col3) where Col1 is not null group by Col1 label sum(Col3)''")
G2:
={FILTER(B2:C, A2:A=E2); "", SUM(FILTER(B2:C, A2:A<>E2))}
I2:
={"", SUM(FILTER(C2:C, A2:A=E2)); FILTER(B2:C, A2:A=E3); "", SUM(FILTER(B2:C, A2:A=E4))}
K2:
={"", SUM(FILTER(B2:C, A2:A<>E4)); FILTER(B2:C, A2:A=E4)}
demo sheet

Google Sheets help - How to apply COUNTIFS with different size criteria ranges

I understand that for COUNTIFS, you need to have ranges that are the same size and shape. However, I need one condition to be that the ID# in the cell matches the ID # in a one column range AND that the age in the cell matches the age value in a five column range. How can I work around this?
Sample sheet: https://docs.google.com/spreadsheets/d/1i6qFmJ1t7yDpGVSO8YOPnWqW_OZEz6fv4shTOBO-q3M/edit?usp=sharing
In cell A7 of the 'Analysis' tab I entered
=query(ArrayFormula(regexreplace(split(flatten(Masterfile!A2:A&"_"&Masterfile!B2:F), "_")&"", "\d+\smonths", "0")), "Select Col1, count(Col1) where Col2 <>'' group by Col1 pivot Col2")
See if that works for you?

Google Sheets: Selecting which sheet the column you want to select in query

is there a way to manually select which sheet to select in query when you are importing multiple sheets?
for example i have the following data
spreadsheet 1(Animal Sheet)
header1 header2 header3
cat white 10
dog black 20
mouse brown 30
duck white 40
spreadsheet 1(Car Sheet)
header1 header2 header3 header4
honda red van 50
toyota yellow car 60
porsche pink car 70
bmw brown suv 80
Spreadsheet 2
im using the formula
=QUERY(
{
IMPORTRANGE("key-or-url-of-spreadsheet-1", "'Animal'!A1:Z100");
IMPORTRANGE("key-or-url-of-spreadsheet-1", "'Car'!A2:Z100");
},
"SELECT Col1,Col2,Col3,Col4 WHERE Col1 IS NOT NULL"
)
but with this formula it will show column 3 of spreadsheet 1(car sheet) which i want to be excluded
what i want to happen is
header1 header2 header3
cat white 10
dog black 20
mouse brown 30
duck white 40
honda red 50
toyota yellow 60
porsche pink 70
bmw brown 80
combine both sheets but exclude column 3 in Spreadsheet 1(Car Sheet)
is there a way to do this?
As one modification, how about the following modification?
Modified formula:
={
QUERY(IMPORTRANGE("key-or-url-of-spreadsheet-1", "'Animal'!A1:Z100"),"SELECT Col1,Col2,Col3 WHERE Col1 IS NOT NULL");
QUERY(IMPORTRANGE("key-or-url-of-spreadsheet-1", "'Car'!A2:Z100"),"SELECT Col1,Col2,Col4 WHERE Col1 IS NOT NULL")
}
In this modification, the columns you want to retrieve are retrieved from each range using QUERY.
Result:
References:
IMPORTRANGE
QUERY
From my point of view, the cleanest solution would be to align the columns you have in your spreadsheet Car to the ones of your spreadsheet Animal, like this:
header1 header2 header3 header4
honda red 50 van
toyota yellow 60 car
porsche pink 70 car
bmw brown 80 suv
And then in your query have only the first 3 columns being called:
=QUERY(
{
IMPORTRANGE("key-or-url-of-spreadsheet-1", "'Animal'!A1:Z100");
IMPORTRANGE("key-or-url-of-spreadsheet-1", "'Car'!A2:Z100");
},
"SELECT Col1,Col2,Col3 WHERE Col1 IS NOT NULL"
)

Using query to search through table based on vertical and horizontal values

I have a table for employees and dates, I want to find out how many cases they solved on an exact date. I tried using a query but it's not working for me as its a new challenge for me to make a query that works based on the horizontal and vertical values. here is an example:
https://docs.google.com/spreadsheets/d/19x2jGYM7xt_WIZN_OGPwTe_7q26Jj57l9Z0PUmSv0I8/edit#gid=0
try:
=QUERY(TRANSPOSE(QUERY(TRANSPOSE(A1:H),
"where Col1 matches 'Day|"&I3&"'", 0)),
"select sum(Col2)
where Col1 ="&DATEVALUE(I2)&"
label sum(Col2)''")

How can I count text strings based on adjacent cell?

I have a grid of cells in Google Sheets:
A1 displays the quantity of product code "ABC" in B1, then C1 displays the quantity of the product code "DEF" in D1, it then repeats on the next row for the next customer and so forth.
I am attempting to summarize all of this area at once at the bottom, using some kind of COUNT formula, but haven't been able to figure out how yet.
=QUERY({A:B;C:D},
"select Col2, sum(Col1)
where Col1 is not null
group by Col2
label sum(Col1)'Sumary', Col2'Item'")
=QUERY({A:B;C:D},
"select Col2, count(Col2)
where Col2 is not null
group by Col2
label count(Col2)'Count', Col2'Item'")

Resources