How to get uniques and sum based on criteria set in Google Sheets? - google-sheets-formula

I'm trying to get these summed, but I can't wrap my head around it.
Here is a visual demo:
Here is the link to the sheet, in case you feel like jumping in:
https://docs.google.com/spreadsheets/d/1gh5w0czg2JuoA3i5wPu8_eOpC4Q4TXIRhmUrg53nKMU/edit?usp=sharing
I did an INDEX+MATCH, but of course this isn't going to get me anywhere:
=iferror(INDEX(E:E;MATCH(1;(F:F=I$6)*(A:A=$H$7);0));"-")

You can do two nested QUERY to find the uniques (by counting them), and only selecting them the column of numbers. The first QUERY also filters by date and type:
=SUM(QUERY(QUERY(A:F;"SELECT A,B,E,COUNT(A) where A = '"&H7&"' AND F = date'"&TEXT(I6;"yyyy-mm-dd")&"' group by A,B,E");"SELECT Col3"))
As an array to include more all the dates:
=MAKEARRAY(2;COUNTA(I6:6);LAMBDA(r;c;SUM(QUERY(QUERY(A:F;"SELECT A,B,E,COUNT(A) where A = '"&INDEX(H7:H8;r)&"' AND F = date'"&TEXT(INDEX(I6:6;;c);"yyyy-mm-dd")&"' group by A,B,E");"SELECT Col3"))))

Added working solution to your sheet here:
=MAKEARRAY(2;COUNTA(I6:O6);LAMBDA(r;c;SUM(LAMBDA(z;MAP(INDEX(z;;1);INDEX(z;;2);INDEX(z;;3);LAMBDA(a;e;f;IFNA(FILTER(e;a=INDEX(H7:H8;r);f=INDEX(I6:O6;;c))))))(UNIQUE({A:A\E:E\F:F})))))

Related

Get newest date in Sheet

i have a sheet with two tabs. In the first tab, i can select a site and i have a list of types. I have a second tab with many datas from each type (date, year, month week, and site attached to a type).
I would like in the first tab write a formula to automatically get the newest date of the type depending to the selected site.
I'm not good with formulas but i tried to write one, this one =IF((AND(C1=DATA!F:F),(B3=DATA!E:E)),LARGE(DATA!A:A),"") but i don't have result.
Anyone can help me with my problem please ? This is the link of my Sheet.
=INDEX(SORT(FILTER( DATA!A:A; DATA!F:F = $C$1; DATA!E:E = $B3); 1; FALSE);1)
=INDEX(SORT(FILTER( DATA!A:A; DATA!F:F = $C$1; DATA!E:E = $B4); 1; FALSE);1)
INDEX(array, [row])
Index gets the nth value in an array, when you pass in the value 1, it will get the top most value.
I created a sorted array by using the FILTER function. and the SORT function. I sorted it descending and only returned the dates in the FILTER function.

Google Sheets - Can't find what's wrong with my Query function based on Today() function

I've gone through the many similar questions for the past two days and can't seem to find what's not working.
My function is:
=IFNA(QUERY(A2:I,"select B,C where F = date '"&text(today(),"yyyy-MM-dd")&"'",1),"")
Where I'm trying to query all the first+last names in columns B, C if their corresponding date in F is today.
But instead, it just queries the entire columns, regardless of the corresponding dates.
It's so annoying, please help me fix the function :)
If you want first & last names in different column
Try this: =ArrayFormula(IFERROR(SPLIT(IF(C1:C=TODAY(),A1:A&" "&B1:B,"")," ")))
For you range: =ArrayFormula(IFERROR(SPLIT(IF(F2:F=TODAY(),B2:B&" "&C2:C,"")," ")))
If you want first & last name in same cell
Try this: =ArrayFormula(IF(F2:F=TODAY(),B2:B&" "&C2:C,""))
Arrayformula()
If function

In Google Sheets - find word within cell, return cell without word

I have a google sheet with a column of item names, (i.e. "Amy dress, Brooke Tshirt, etc.) Some of these items have a prefix - JK or JL (JK - Amy Dress, JL - Brooke Dress) in addition to the non-prefixed versions. I'm trying to find a way to search for a prefix (JK - ) and return the item name associated with that prefix in a different column.
Search for "JK - ", find JK - Amy Dress, return Amy Dress. Please help!
Tried lookup and match, but this is too complicated for my skill set.
You can try to use a Google Sheets Query.
If you want something like this:
Based on the table above the query you'll have to use will be:
=query(A:B;"select * where B Starts with 'JK'";-1)
If you want to select only the B column just remove the A:
=query(B;"select * where B Starts with 'JK'";-1)
The query automatically creates a new "table" with all the values you need.
If you want to make it customizable use the following query:
=query(A:B;"select * where B Starts with '"&$G1&"'";-1)
In this case instead of "JK" we are searching something that starts with the content of the cell G1. So if you type JK in the G1 cell you will obtain the same result as before.
Hope it helps.

Simpler alternative to simultaneously Sort and Filter by column in Google Spreadsheets

I have a spreadsheet (here's a copy) with the following (headered) columns:
A: Indices for a list of groceries;
B: Names for the groceries to be indexed by column A;
C: Check column with "x" for inactive items in column B, empty otherwise;
D: Sorting indices that I want to apply to column B;
Currently, I am getting the sorted AND filtered result with this formula:
=SORT(FILTER(B2:B; C2:C = ""); FILTER(D2:D; C2:C = ""); TRUE)
The problem is that I need to apply the filter two times: one for the items and one for the indices, otherwise I get a mismatch between elements for the Sort function.
I feel that this doesn't scale well since it creates duplication.
Is there a way to get the same results with a simpler formula or another arrangement of columns?
=SORT(FILTER({Itens!B2:B\Itens!G2:G}; Itens!D2:D=""))
=SORT(FILTER({Itens!B2:B\Itens!G2:G}; Itens!D2:D="");2;1)
or maybe: =SORT(FILTER(Itens!B2:B; Itens!D2:D="");2;1)

extract elements from xml document

I have an xml document in which I want to extract every 10 elements. I used this code to extract the last 10 elements, but the idea is to get the next 10 ones just before them, I can't use pagination with linq since I get the whole document:
slideView.ItemsSource =
(from channel in xmlItems.Descendants("album")
orderby (int)channel.Element("catid") descending
select new onair
{
title = (string)channel.Element("name"),
photo = (string)channel.Element("picture")
}).Take(10);
any ideas please?
Thanks
Try .Skip(10).Take(10) towards the end of your query.

Resources