Calculated field over list of values - arrays

Given this table of data:
I'd like to produce this pivot table:
I have an inkling this can be done with the calculated field, and SUMIF, but am not able to get it to work. I think the main blocker is that I'm not able to find good documentation for what I can reference inside of a calculated field formula. My best attempt was =SUMIF(color, "RED")/SUM(), but that produced zeros.
Example table at https://docs.google.com/spreadsheets/d/16htOLbwf47Neo68iFlm9OvFVS_u2Jlc-2thhdUQwrpU/edit?usp=sharing
Any guidance appreciated!

={QUERY(A1:B25,"select A,count(A)/"&COUNT(A:A)&" where B='RED' group by A label count(A)/"&COUNT(A:A)&" 'PCT RED'");{"Grand Total",COUNTIFS(A:A,">=0",B:B,"RED")/COUNT(A:A)}}
Function References
Query
COUNT
COUNTIFS
I think my concern here would be that with a normal pivot table it's robust against data moving around. This seems to break that by referencing specific columns
Method pivot table you must show all color

I think my concern here would be that with a normal pivot table it's robust against data moving around. This seems to break that by referencing specific columns
to "set it free" you can do:
={QUERY({A:B},
"select Col1,count(Col1)/"&COUNT(A:A)&"
where Col2='RED'
group by Col1
label count(Col1)/"&COUNT(A:A)&"'PCT RED'");
{"Grand Total", COUNTIFS(A:A, ">=0", B:B, "RED")/COUNT(A:A)}}

Related

Vlookup within results of a multiple-match lookup

I am trying to find a way to return values from a table like the bottom table:
The tables are provided externally and my understanding is that I can't run filters or sorts as the table is full of extra irrelevant data that would not sort properly across all columns.
I'm approaching this twofold:
firstly, I wanted to return the row information for any entry in the table that has a CPT matching the lookup value.
Second, (where I'm stuck)--when the lookup returns a DESC that corresponds to a matched CPT, the goal would be to also pull in any Code A/Code B entries that correspond to that DESC value.
I found an existing formula that worked for the first part, shown below. (apologies for formatting--SO keeps flagging my draft as having unformatted code).
IFERROR(INDEX($B$3:$B$3000,SMALL(IF(I$2=$A$3:$A$3000,ROW($A$3:$A$3000)- MIN(ROW($A$3:$A$3000))+1,""), ROW()-1)),"")
Currently, the aforementioned formula does return the DESC entries for any matching CPTs and I use vlookup to pull the rest of the relevant columns for a corresponding row.
I'm coming up short in cases where there are multiple Code A/Code B entries for a given DESC, as the lookup only returns information for the row containing the matching CPT and not any relevant codes contained in subsequent rows.
I was thinking I'd have to use something similar to the existing lookup formula to identify a matched row and then display any subsequent rows containing Code entries until the next row with a non-blank CPT entry.
Unfortunately, I don't know if that's actually the best way to approach this. Any resources/suggestions are greatly appreciated.

How to Use Excel Spill Range To Convert Multi-Column Array into Two Column Array

I'm trying to create a spill-range solution to turn a list of dates and multiple columns of names into a structured two columns of data. I can do this using VBA, but because this will be automated and web-based, I need a spill-range solution.
A sample file of my situation can be found in this file.
As you'll see below, I have a list of a set of employees ("slackers") who have requested vacation/PTO during December. I've created a list of two spill range formulas that are:
A Column listing all days December
A list of slackers requesting the day off (array going horizontal).
Part 2 presents the problem as the the number of slackers is inconsistent and I'm not sure how to create additional dates for each row. Thus my problem is how to structure a filter/Array formula to list each employee, by day.
In the following tab, you can see my desired outcome. I've used a macro to generate this, but because this is web-based, I cannot use it.
I've tried a variety of mixing and matching array formulas and filters but cannot find a way to populate the date with each name.
While my question is scoped to addressing this conversion from multi-column to 2-column approach, I am happy to hear comments addressing the overall concept.
Here it is with your datatable:
=LET(
end, PtoRequestsTable[End],
strt, PtoRequestsTable[Start],
us, PtoRequestsTable[Slacker],
usCnt, COUNTA(us),
lst, DATE(YEAR(TODAY()),12,1),
led, DATE(YEAR(TODAY()),12,31),
dtSq, INT(SEQUENCE((led-lst+1)*usCnt,,lst,1/usCnt)),
md, MOD(SEQUENCE((led-lst+1)*usCnt,,0),usCnt)+1,
ussl, IF((INDEX(end,md)>=dtSq)*(INDEX(strt,md)<=dtSq),INDEX(us,md),""),
SORT(FILTER(CHOOSE({1,2},dtSq,ussl),ussl<>""),1,-1)
)
It will automatically grow and shrink with the table. It also has the start and end dates as inputs.
You may need to adjust maxWidth if there are more than 8 potential slackers.
=LET(maxWidth,8,
days,ByDay!A2#,
slackerBox,OFFSET(days,,1,,maxWidth),
ndx,SEQUENCE(ROWS(days)*maxWidth),
ndxDay,INT(ndx-1)/maxWidth+1,
slackerList,INDEX(slackerBox,ndxDay,MOD(ndx-1,maxWidth)+1),
FILTER(CHOOSE({1,2},INDEX(days,ndxDay),slackerList),slackerList<>0))

What is the best way for refactoring excel formula

Like I ask in title, what is the best way to write formula like this one below. I want sum from all sheets values for Germany (values are in B column)
=SUM(SUMPRODUCT(--(First!A2:A11="Germany"),(First!B2:B11)), SUMPRODUCT(--(Second!A2:A11="Germany"),(Second!B2:B11)), SUMPRODUCT(--(Third!A2:A11="Germany"),(Third!B2:B11)))
What is your opinion?
In Google Sheets you can also use
=QUERY({L1:M9;O3:P7},
"select sum(Col2) where Col1 ='xxx' label sum(Col2) 'Total' ",1)
(Please adjust ranges to your needs)
How the formula works.
We create an array using curly brackets {} stacking the ranges one on top of the other using semi-columns ; even from other sheets like {L1:M9;O3:P7;First!A2:B11;Second!A2:B11}. One can add as many ranges as needed. Even open ranges.
The ,1 in the end of the formula shows that the very first row will be treated as a header row.
Please read more about the QUERY. function
try:
=SUM(FILTER({First!B2:B11; Second!B2:B11},
{First!A2:A11; Second!A2:A11}="Germany"))
One more option:
=SUMPRODUCT(({First!A2:A9;Second!A2:A9}="Germany")*{First!B2:B9;Second!B2:B9})

In GridDB, can an index/rowkey/search be inverted?

Using GridDB, I sometimes need to read data starting with the first row, and sometimes starting with the last row. Currently I have two containers with the same data but inserted in the opposite order of each other. While functional, this does seem rather inefficient.
So the question is: are there better ways to do it? Can the rowkey, or an index assigned to a container be inverted with a function call? Or is there a way to adjust the search accordingly?
You're looking for the TQL ASC or DESC operator which will invert the order data is returned.
If you actually want an inverted index a timestamp I would add a field to your schema and when inserting data, insert (LLONG_MAX - timestamp)

Generate hyperlink from query

My query is not returning the literal cell value, but rather only the visual portion of it.
I've got a google spreadsheet with FirstSheet having my info and then with the use of a query on SecondSheet showing part of the information.
The first column of FirstSheet has a hyperlink for each row in column A such as:
=hyperlink("http://www.google.com/test","My Test")
SecondSheet has a query that pulls that column amongst others such as:
=query('FirstSheet'!A2:C;"select*",0)
The query result only returns the label of the hyperlink but not the link itself or the hyperlink formula. Meaning I see the same text on both sheets but on SecondSheet it's not a link. I hope this makes sense.
I've thought about different ways to accomplish this including some how creating a string from a query to give me what I want, but I'm not sure. Any help would be greatly appreciated.
I solved it by moving the query to B2, selected column A last, putting it into Col C, hid C. I'm then using C with a formula I created in col A and then just pasted that formula down to row 100.
=If (C2="","",hyperlink("http://www.google.com/"&C2,C2))
I would have liked this to be more elegant, but it's good enough for now.

Resources