Select value of first row where column value matches - arrays

I have two sheets in the Google sheet with the following pattern and data
raw sheet
Projects
start date
end date
status
Proj1
July 1, 2021
July 10, 2022
In Progress
Proj2
July 11, 2021
July 20, 2022
Done
Proj1
July 21, 2021
July 25, 2022
Done
and another sheet
project analysis
Projects
start date
end date
status
Time taken (days)
Proj1
July 1, 2021
July 25, 2022
Done
24
Proj2
July 11, 2021
July 20, 2022
Done
10
The values in the project analysis has been manually field, but I want it to automate as follow
set start date in project analysis to the start date column of the first entry from raw sheet
set end date in project analysis to the end date column of the first entry from raw sheet where status is Done
How can I accomplish this in Google sheet?

try:
=ARRAYFORMULA(QUERY({A:C, B:C*1},
"select Col1,min(Col2),max(Col3),'Done',max(Col5)-min(Col4)
where Col1 is not null
group by Col1
label min(Col2)'start date',max(Col3)'end date','Done''status',max(Col5)-min(Col4)'time taken in days'", 1))

In excel ---
Formula in Column B
=VLOOKUP(A13,$A$2:$B$4,2,FALSE)
Array formula in Column C
=INDEX($C$2:$C$4,MATCH(1,(A13=$A$2:$A$4)*("Done"=$D$2:$D$4),0))
Refer INDEX and MATCH with multiple criteria
Formula in Column D
=IF(NOT(ISNA(C13)),"Done","In Progress")

start date:
=ArrayFormula(IF(A2:A="",,VLOOKUP(A2:A,raw!A:B,2,FALSE)))
end date:
=ArrayFormula(IF(A2:A="",,VLOOKUP(A2:A,FILTER(raw!A:C,raw!D:D="Done"),3,FALSE)))

Related

How do you count Distinct Customers and group by first month seen?

I have a series of customers over the course of the year that I need to group into two categories: New and Reoccurring.
The data roughly looks like this:
ID
Date Seen
1
August 1, 2022
2
August 3, 2022
2
July 1, 2022
2
June 1, 2022
3
July 1, 2022
3
August 1, 2022
New customers would show up on the month that we see their first record. Reoccurring would have more than 1 month logged with us.
How would I count these two groups?
So as an example above, I'd expect to see:
Month
Trial
Returning
August
1
2
July
1
1
June
1
0
Edit: Per request here's a link to a Data Studio report with mock data.
Added the solution to your dashboard.
created a blend and used a calculated field to pivot the data
CASE WHEN Month (Table 1)=Month (Table 2) THEN 'TRIAL' ELSE 'RETURNING' END

Honeycomb Date range picker issues

I was shown in date range picker past 60 from today date.when I try to select this month date its shows future month.
Example
When I select date range from sep 1 to sep 3 its shows Oct month but actually its not the it will shows only past date

How do I get last 12 months of data based on available data in SQL Server

I have a table test with columns sales and date. The requirement is to get the last available 12 months of data without the current month. For example say that there is data available till 2010 march 5th. The query needs to fetch data from 2009 march till 2010 feb. what would be the where clause on date be in SQL Server
SELECT Sales, Date FROM Test
WHERE Date BETWEEN
DATEADD(m,-12,DATEADD(m, DATEDIFF(m, 0, '05/Mar/2010'), 0))
AND
DATEADD(m, 0,DATEADD(m, DATEDIFF(m, 0, '05/Mar/2010'), 0)) - 1

SQL Query-Multiple date ranges

I want to fetch some data from DB by giving multiple date ranges. Example,in February I want to get weekly report from a table in this order Feb 01 to 07, Feb 07 to 14, Feb 14 to 21, Feb 21 to 28 and Feb 28 to Mar 01. In DB the records are stored in a daily wise not in weekly wise. I want to cluster it as weekly wise and calculate sum then show the result. Please help me if you know this case.
For clear cut view, consider 3 tables & its columns.
Table A:id,timestamp (comment-data is inserted daily)
Table B:id,fruits
Table C:id,fruits_type
Result:
fruits_type count(id) timestamp
apple 3 01-02-2016 to 07-02-2016
orange 5 01-02-2016 to 07-02-2016
pineapple 8 01-02-2016 to 07-02-2016
apple 4 07-02-2016 to 14-02-2016
orange 5 07-02-2016 to 14-02-2016
Conditions:id should match among 3 tables;fetch data by providing group by fruits_type and timestamp should be in weekly wise.
Please help if you know this
To get the sum of all values between two dates you would do it like this:
SELECT SUM(Column1)
FROM Table1
WHERE Date1 BETWEEN '2/1/2016' AND Date1 <'2/7/2016'
If you want to make it more flexible and have the query get the last week's sum you can use the DATEADD function to lag by one week:
SELECT SUM(Column1)
FROM Table1
WHERE Date1 BETWEEN DATEADD(week, -1, GETDATE()) AND Date1 < GETDATE()
If you want the result set to include a row for each week, you can use UNION to merge the queries.

filter for multiple record based on latest timestamp

I have the following table:
Record Created Name Group
1 July 23, 2015 John Group 1
2 July 21, 2015 April Group 1
3 April 4, 2015 John Group 1
How do you filter for the latest distinct record? In this example, I would expect to get record 1 and 3? My code:
Model.objects.filter(Group='Group 1').latest('Created')
only grabs record 1.
latest return an object (row) that is, well, "latest" based on specified field provided as argument.
If you need several records (rows) then you need to get a QuerySet.
Try:
YourModel.objects.filter(Group='Group 1').order_by('-Created')[:2]
this should give you rows 1 and 3 as you expect.

Resources