Sum Range with Multiple range condition - google-sheets

I have this data in 2 google sheet tables
First table :
Product Group
Product
Group A
Product x
Group A
Product y
Group B
Product z
Group B
Product x
Second Table :
IV
Product
Revenue
Date
IV-01
Product x
10$
1 Jan
IV-02
Product y
15$
2 Jan
IV-03
Product z
25$
5 Jan
I need to sum value of my Revenue of Product Group A within Date Range 1-2 Jan. What formula should I do?
I have tried
=sumproduct(Table2!C1:C * Table2!B:B=filter(Table1!B:B,Table1!A:A = Product Group A) * Date range)
But it doesn't work.

This may help
=SUM(
FILTER(
F2:F4,
VLOOKUP(E2:E4,{B2:B5,A2:A5},2,0)="Group A",
G2:G4>=DATE(2021,1,1),
G2:G4<=DATE(2021,1,2)
))
The approach is based on the next formula
=ARRAYFORMULA(
VLOOKUP(E2:E4,{B2:B5,A2:A5},2,0)="Group A"
)

Related

SUMIFS With Text and Date Comparison

theoretically I want to sum the total income each employee made for all the businesses.
Like this:
Employee 1 = Biz 1 income + Biz 2 income + Biz 3 income, etc...
Employee 2 = Biz 1 income + Biz 2 income + Biz 3 income, etc...
Technically and based on the table below, I want to sum a range in column R starting from cell R14 where the text in column W starting from W14 is the same in column P starting from cell P14 AND the name of the month in column V starting from cell V14 is equal to a month in date in column N starting from cell N14.
*
(I included the date because this is part of a budget planner so I need to categorize the data based on months.)*
I used this formula:
=SUMIFS(R14:R1013, P14:P1013, U14:U1013, TEXT(N14:N1013,"MMMM"),"="&T14:T1013)
But it prompts me with the error: Array arguments to sumifs are of different size
What could be wrong here? Does someone have any idea?
Thanks for your help in advance!
Try wrapping the text formula into ARRAYFORMULA to get the full column:
=SUMIFS(R14:R1013, P14:P1013, U14:U1013, ARRAYFORMULA(TEXT(N14:N1013,"MMMM")),"="&T14:T1013)
You can get the totals for all months and all employees with query(), like this:
=arrayformula(
query(
{ text(N13:N, "yyyy-MM"), O13:R },
"select Col1, Col3, sum(Col5)
where Col3 is not not null
group by Col1, Col3",
1
)
)

How to calculate a sum conditionally based on the values of two other columns

Feels like this may be a basic, but I cannot find a way to do this with sumifs.
I've got four columns in one table, representing the workload of an employee like this:
Job
Employee # 1
Employee # 2
Workload
Job 1
Bob
Jane
5
Job 2
Bob
2
Job 3
Jane
Susan
3
Job 4
Susan
2
I'd like to output total workflow results to a second sheet for each employee based on a specialized formula. In English, the forumla would be:
Calculate the total workload for each employee.
- For each job that includes that includes employee named "X" and no assigned teammate, use the job's corresponding workload value.
- For each job that includes that includes employee named "X" and has an assigned teammate, reduce the corresponding workload value by 50%.
So with the given table above, I'd want an output like this:
Employee Name
Workload
Bob
4.5
Jane
4
Susan
3.5
Math:
Bob = ((job_1 / 2) + job_2)
Jane = ((job_1 / 2) + (job_3 / 2))
Susan = ((job_3 / 2) + job_4)
Does anyone know how I can accomplish this?
Functions like sumifs seem to only let me set criteria to sum or not sum a value. But I cannot find a clear way to sum only 50% of a value based on a condition in a separate column.
=LAMBDA(name,SUMIFS(D2:D5,B2:B5,name,C2:C5,"")+SUMIFS(D2:D5,B2:B5,name,C2:C5,"<>")/2+SUMIFS(D2:D5,C2:C5,name)/2)("Bob")
The math is
SUM D, if B is Bob and C is empty and
SUM half of D if B is Bob and C is not empty and
SUM half of D, if C is Bob.
Or the same logic via query:
=QUERY(
{
QUERY(B1:D5,"Select B,sum(D) where C is null group by B");
QUERY(B1:D5,"Select C,sum(D)/2 where C is not null group by C");
QUERY(B1:D5,"Select B,sum(D)/2 where C is not null group by B")
},
"Select Col1, sum(Col2) where not Col1 contains 'Employee' group by Col1"
)
However, note that we're assuming title contains Employee and no other names contain Employee.
Employee # 1
sum sum Workload
Bob
4.5
Jane
4(Incorrect in the question)
Susan
3.5
Use this formula
=ArrayFormula({ "Employee Name", "Workload";
QUERY(
QUERY({LAMBDA(a,b,c,d,k, {b,a,{d/k};c,a,{d/k}} )
(A2:A,B2:B,C2:C,D2:D,
BYROW(B2:C, LAMBDA(c, IF(COUNTA(c)=0,,IF(COUNTA(c)=1,1,2)))))},
"Select (Col1),sum(Col3) Group by Col1" ,0), "Where Col1 <> '' ",0)})
Used formulas help
ARRAYFORMULA - QUERY - LAMBDA - BYROW - IF - COUNTA - SUM

Google sheets use a filter on date and category in one go

I am trying to sum up values in google sheets. I want a monthly overview and a sum per category.
My data has these characteristics:
date, category, value
01-01-2021, blue, 50
02-01-2021, green, 100
01-02-2021, blue 50
15-01-2021, orange, 30
12-02-2021, orange, 50
18-01-2021, blue, 20
I want to group it as follows:
month, category, value
January, blue, 70
January, orange, 30
February, blue, 50
February, green, 100
February, orange, 50
I managed to sum values that are between certain dates. So combining the date and value column as in above example. Now I would like to add the category to it.
My function:
=SUMIFS(F2:F362;B2:B362;">="&D3;B2:B362 ;"<="&D4)
F2:F362 is the range of the values
B2:B362 is the range of the dates
D3 = Minimal date
D4 = maximum date
Any help or tips would be appreciated! Not sure if I should continue in this function or add something around it. Couldn't find this combined challenge in current questions, only the separate ones.
try:
=QUERY(A1:C,
"select month(A)+1,sum(C)
where A is not null
group by month(A)+1
pivot B
label month(A)+1'month'", 1)
or the reverse distribution:
=QUERY(A1:C,
"select B,sum(C)
where A is not null
group by B
pivot month(A)+1", 1)
to add external date boundaries:
=QUERY(A1:C,
"select B,sum(C)
where A >= date '"&TEXT(D3, "yyy-mm-dd")&"'
and A <= date '"&TEXT(D4, "yyy-mm-dd")&"'
group by B
pivot month(A)+1", 1)

Sum column in google excel using 2 conditions

I have a table with 4 columns in a google spreadsheet [timestamp, item, amount, category] and would like to get all rows that belong to a specific month and a specific category and sum the amount column.
So far I have tried
=QUERY(Sheet1!A:D,"SELECT SUM(C) WHERE MONTH(A) = 1 AND D = 'some text' GROUP BY A",1)
and
=IF(AND(EQ(Sheet1!D2:D,B17),MONTH(Sheet1!A2:A)=1),SUM(Sheet1!C2:C))
Where B17 is a text that I want a comparison to be made.
In Google spreadsheets, try
=sumproduct(Sheet1!D2:D=B17,MONTH(Sheet1!A2:A)=1, Sheet1!C2:C)
and see if that works?
If you'd prefer query, you can try
=QUERY(Sheet1!A:D,"SELECT SUM(C) WHERE MONTH(A) = 0 AND D = '"&B17&"' label SUM(C) ''",1)
Note that MONTH() in query is zero-indexed: so January would be month 0.
You can change this one:
=IF(AND(EQ(Sheet1!D2:D,B17),MONTH(Sheet1!A2:A)=1),SUM(Sheet1!C2:C))
with
=sum(filter(Sheet1!C2:C,(Sheet1!D2:D=B17)*(MONTH(Sheet1!A2:A)=1)))

How do I get Google Sheets to Find First Instance at or above a Numerical Value in a Column of Values?

I am building a Google sheet to count the # of days a dividend stock returns to or above the price it closed before the ex-dividend date.
So I have a table with two columns for the stock I'm looking at, with 1st column being the Date, 2nd column the high price the stock hit during that day.
So in column D, I have the date before ex-div date, and in column E, I have the stock closing price on the date in E.
In columns G & H I have the next 3 months worth of days (in column G) and stock daily high prices (in column H).
I tried to use =match to count the days until the stock price returns to equal or above the closing price on the date in column E, but while it returns a numerical value, it is not accurate.
=MATCH(E2,H2:H,1)
I'd like the formula to return the number of days the stock took to recover.
maybe like:
=DAYS(INDIRECT("G"&MATCH(E2, H:H, 0)), D2)
UPDATE:
how to get to the first date from Column G that matches or exceeds the price in column E (and return the # of days in F2 for that date)
=DAYS(QUERY(G2:H, "select G where H >= "&E2&"limit 1", 0), D2)
=min(filter(date column, value column>minimum value))

Resources