I'm fairly new to Google Sheets and know very basic about the functions. I'm trying to create a sheet to keep record of buy/sell of different items and then generate a report where i can see the profit and remaining item in stock , avg buy/sell price etc. Here's a link to sample sheet and what I've tried.
Please let me know if it can be achieved, if yes what I need to look for, any sample or link to learn in proper direction to achieve what I'm trying to get. Attaching screen shot to give a quick glimpse.
Query I used :-
=QUERY(A2:F9,"select A,B,Sum(C),Sum(E) group by A,B Label Sum(C) 'Total Quantity',Sum(E) 'Total Price'")
Thank you.
PS. I have it posted earlier in google group as well. I'll link it back there if I come to any solution.
I couldn't find a simple and neat way of achieving the layout that you wanted, but you can use Index to pull out a row and column from your query based on the row and column containing the formula like this (for the first column)
=if(int(rows($1:3)/3)<=countunique($A$2:$A$9),choose(mod(rows($1:3),3)+1,index(QUERY($A$2:$F$9,"select A,B,Sum(C),Sum(E) group by A,B Label Sum(C) 'Total Quantity',Sum(E) 'Total Price'") ,int(rows($1:3)/3)*2,1),"","Total"),"")
Then it works out whether it is the first, second or third row of a group in the report and uses the Choose function to put in the item name, a blank cell or the word "Total".
The second column works in the same sort of way
=if(int(rows($1:3)/3)<=countunique($A$2:$A$9),if(mod(rows($1:3),3)<2,index(QUERY($A$2:$F$9,"select A,B,Sum(C),Sum(E) group by A,B Label Sum(C) 'Total Quantity',Sum(E) 'Total Price'") ,int(rows($1:3)/3)*2+mod(rows($1:3),3),2),""),"")
The first Mod function is used to work out if it should show "b" or "s" from the query, or a blank, and the second Mod function works out whether it should be the "b" or "s" row of the query.
The third column is also similar
=if(int(rows($1:3)/3)<=countunique($A$2:$A$9),if(mod(rows($1:3),3)<2,index(QUERY($A$2:$F$9,"select A,B,Sum(C),Sum(E) group by A,B Label Sum(C) 'Total Quantity',Sum(E) 'Total Price'") ,int(rows($1:3)/3)*2+mod(rows($1:3),3),3),L11-L12),"")
The first Mod function is used to work out if it should show the quantity from the query, or the difference of the two previous rows, and the second Mod function works out whether it should be the "b" or "s" row of the query.
The fourth column is almost identical to the second one.
=if(int(rows($1:3)/3)<=countunique($A$2:$A$9),if(mod(rows($1:3),3)<2,index(QUERY($A$2:$F$9,"select A,B,Sum(C),Sum(E) group by A,B Label Sum(C) 'Total Quantity',Sum(E) 'Total Price'") ,int(rows($1:3)/3)*2+mod(rows($1:3),3),4),""),"")
(I couldn't work out how the Actual Profit should be calculated).
Related
In cell B1, how to write a Query Function to filter sales from "Data" sheet, When I paste any salesman list into A1:A9999 , it would shows sales amount for each salesman.
The result should be as follow:
https://docs.google.com/spreadsheets/d/1h2x-KgeBhOmiKpbx0EkWW6liZWMQ3w1mC7uTkCOy1tE/edit?usp=sharing
Thank you so much for your help.
use in B1:
={"Q"; INDEX(IFNA(VLOOKUP(A2:A, Data!B3:E, 4, 0)))}
Here's another solution:
={"Sales"; arrayformula(if(A2:A<>"",iferror(vlookup(A2:A,query(Data!A1:E,"Select B, sum(E) where B is not null group by B label sum(E) ''",0),2,false),"Not Found"),""))}
The difference for this formula is that it will return your selected salesman's total sale (if ever your data will have multiple salesman entries)
Example: (I modified your data sheet for this example)
Output:
I can't quite wrap my head around how to do the following: I have two sheets, with some results that reflect some counts. I want to calculate a percentage of the counts between the two sheets. The issue is that the data is dynamic, and the second sheet does not always have matching results... And the results are LARGE.
Here's a sample sheet:
https://docs.google.com/spreadsheets/d/1b3ap33kW7ErwF3PcwGPvtv_I3tR0TNdyuurJdHY1Fjk/edit?usp=sharing
I do know that for just a basic array formula percentage I can use this:
=arrayformula(iferror(A2:A/B2:B))
This work as long as the columns always match but in this case, they won't.
As seen on the sample sheet linked, I was able to achieve the results in the second tab by getting the "unique" from the first tab, but that shows users that did NOT have "reworked" tickets. I want to clean it up so that the only percentages shown are for assignees that do have reworked tickets.
I'm not sure how to tell it to only calculate if there's a "match" from '90 day resolved reworked'!B2 and '90 day resolved'!B2
Any insight would be greatly appreciated...
for a count, you can use QUERY formula:
=QUERY(A2:A, "select A,count(A) where A is not null group by A label count(A)''", 0)
to align things you can use VLOOKUP formula:
=ARRAYFORMULA(IFERROR(VLOOKUP(C:C, F:G, {1,2}, 0)))
if you want to calculate straight the percentage without QUERY midstep do:
=ARRAYFORMULA({UNIQUE(FILTER(A2:A,A2:A<>"")),
TEXT(QUERY(A2:A, "select count(A) where A is not null group by A label count(A)''")/
IFERROR(VLOOKUP(UNIQUE(FILTER(A2:A,A2:A<>"")),
QUERY('90 day resolved'!A2:A, "select A, count(A) group by A", 0), 2, 0)),"#.00%")})
demo spreadsheet
Hi I have this sample sheet: https://docs.google.com/spreadsheets/d/1TzKlEAF5IcZehmyyRUQ5ELE63Q-ZVfp9Nfx5-zvKAOc/edit?usp=sharing
I want to pull the data from the left chart. Then I want to sum Same companies revenues. Then I want to put that data dynamically to the right part. I also want to be able to check how much revenue I got from each company each month. I also want to see top 5 companies who made purchase in each month.
So for example: If Company A made 3 purchases in January I want to see sum of these purchases next to company name and sort companies from highest money to lowest for each month.
I wrote a function for that but it doesn't work.
I found the answer and wanted to share here in case anyone would need in the future. This answer belongs to Greg from Google Docs community. I will copy paste the exact answer here:
Hello, See sheet GE.Sheet1. I have added the formulas to demonstrate
your requests.
I want to pull the data from the left chart. Then I want to sum
Same companies revenues. Then I want to put that data dynamically to
the right part.
=QUERY(A:C,"select B, sum(C) where B is not null group by B", 1)
=QUERY(A:C,"select B, A, sum(C) where B is not null group by B, A", 1)
I also want to be able to check how much revenue I got from each
company each month. I also want to see the top 5 companies who made
a purchase in each month.
=QUERY(A:C,"select B, sum(C) where A = '" & M1 & "' and B is not null group by B, A order by sum(C) desc label sum(C) ''", 0)
A limit clause can be added but there is not enough data to test
against. Need more than 5 clients and multiple months.
bests,
GregE
Testing Sheet:
Wondering if there is a witty way to add a Total to the last row +1 of
a Query result.
See Sheet 'Lookup' for a static example of what I am asking for.
I don't know if there is a way to have a hidden column that calculates
transposed only under the last row of a query, or if there is a smart
way to work Query for this answer.
All great answers. Each on very useful in its use case.
Макс Махров gets the answer with using a query statement.
Now I was not keen on having an extra sheet to hold the totals so I added a row at the top which I can simply hide and used this formula:
query({Orders!A:E;A1:E1},"select Col1, Col3, Col4 where Col2 = '"&C3&"' order by Col4",1)
Only problem I have is trying to figure out how to add TEXT to the bottom row, it seems to only want numerical input.
How do I fix this? What am I glitching?
Thanks !
Mars
The trick is to make second query and count totals for selected product.
Plan of actions:
add new sheet with query on it, something like this: =QUERY(Orders!A:E,"select B, 0, sum(D) where B like '"&Lookup!C2&"' Group by B",0)
Prepare arrayformula which combines data in Lookup sheet: = ArrayFormula({Importrange(1),Importrange(2)}) Note that number of columns must retain the same.
Edit query so it takes Col1, Col2, Col3... instead of A, B, C...
Make word 'total' visible instead of zero. Set number format: 0;0;total Set it for range B9:B on Lookup sheet
Make Conditional Formatting with formula =and($B4 =0,isnumber($B4)) for range A4:C on Lookup sheet.
That's seems have to complete the task.
Hope it Helps!
Your Example
Working example.
Here is one way:
Put TOTAL way down in row 1000
Select the range A3:C999. Select data > filter to create filters
Select C3, set the filter to hide all blanks
A second way is to limit the query result to show only the top 8 results:
Change your query to =query(Orders!A:E, "select A, C, D where B = '"&C2&"' order by D desc limit 8",1) It will reverse-order column D (largest first), and set row limit to 8.
Change the formula of your TOTAL to =sumif(Orders!B:B,C2,Orders!D:D)
Try this formula in the column adjacent to your query:
=ArrayFormula({$C$4:offset($C$4,count($C$4:$C),0,1,1);sum($C$4:offset($C$4,count($C$4:$C),0,1,1))})
It duplicates your column of values (I haven't figured out a way around that yet) and then adds a total to the bottom of that column, and changes dynamically with the range from your query.
Here's a working version.
Interesting challenge! It got the old grey matter turning... ;)
Thanks,
Ben
sample attendance (google) sheet
I want count the number of total lates per student name on this sample sheet, e.g, how many lates Mary Love has (actual sheet has over 30,000 rows, 10 columns). If possible, this count needs to change as students have additional lates. I'd really appreciate any help someone might be able to provide. I thank you very much in advance.
In addition to previous post, a QUERY() function also seems a good option as it can output a 2D-array, containing the names and the counts in one formula (no need to drag down). As an example, try:
=query(A:G, "select A, count(B) where B ='Late' group by A ", 1)
If you want to limit the result tho those who had more then 3 late's, you can do:
=query(query(A:G, "select A, count(B) where B ='Late' group by A ", 1), "where Col2 > 3")
Also further filtering with date can be done very easily. However I think that may require some 'cleaning up' of the current data: I noticed a lot of different date formats in col D... :-)
For counting each of several students and to allow greater versatility I suggest a pivot table with Student Name for Rows, Late for Values with Summarise by: COUNTA and Late for Filter with Show: Late.
You can use the COUNTIFS function to get what you are looking for. This formula will count all matches for multiple criteria ranges and criteria (e.g. student name & late).
This is the syntax for the formula:
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)
If you put Mary Love in cell I2, you could then put this in J2.
=countifs(B:B,"=late", A:A,I2)
Then as more rows are added it will automatically update the "lates". I would also suggest using named ranges, then you could replace B:B and A:A with the named range.
I would suggest using the =query function as documented below. If that doesn't meet your needs you could modify the above:
=if (countifs(B:B,"=Late", A:A,I2, D:D, ">="&N2) >= 3, "True", "False")
This will put "True" in the column if there are 3 or more lates, false if not. This will require you put the date you want to check against in column N2. Change N2 above if you want to use a different column.