ArrayFormula retrieve list by multiple criterias - google-sheets

Input
Data sheet
TaskId ClientId Canceled
1 1 0
2 1 0
3 1 0
4 2 0
5 2 1
6 2 0
7 3 0
Report sheet
ClientId
1
1
2
3
Desired Output
Arrayformula to get all TaskIds from Data by clients where Canceled = 0
TaskIds
1
2
3
1
2
3
4
6
7
I have join + filter formula to drag down, which gives me all TaskIds for clients:
ClientId TaskIds
1 1,2,3
1 1,2,3
2 4,6
3 7
Then I get my result from this helper_column:
=transpose(split(join(",", helper_colum)))
And I want to make this work without need to drag down.

Try this:
=ARRAYFORMULA(TRANSPOSE(SPLIT(CONCATENATE("🍻"&TRANSPOSE(IF(TRANSPOSE(A11:A14)=B2:B8,IF(C2:C8=0,A2:A8,""),""))),"🍻")))
A11:A14=Report sheet Client ID.
A2:C8=Data sheet values.
Cheers 🍻

In the 'Report' tab this spreadsheet, cell B2 I entered
=arrayformula(vlookup(A2:A5&"", regexreplace({unique(filter(Data!B2:B, Data!C2:C=0))&"", trim(transpose(query(if((transpose(unique(filter(Data!B2:B, Data!C2:C=0)))=filter(Data!B2:B, Data!C2:C=0))*len(filter(Data!B2:B, Data!C2:C=0)),filter(Data!A2:A, Data!C2:C=0)&",",),,50000)))},",$", ), 2, 0))

Related

Google Sheets: Query and list the last 5 values in a column if the column contains a number

I want to use Sparkline for a spreadsheet to show a trend of the last 5 soccer matches, where A and B are the goals, and C are the resulting points.
In column C, the points are only generated if values are entered for the goals and goals conceded, i.e. the columns are not empty.
A (Goals)
B (Conceded)
C (Points)
4
4
1
4
4
1
4
4
0
3
4
4
1
0
4
0
As you see, in row 3, column c is empty.
What I basically try to achieve, is to create a list where the last 5 entries which are not empty / null, are listed:
C (Points)
1
1
3
1
0
Is used this formula, but it somehow does not work
=query(J15:J114,"select * offset "&count(J15:J114)-5)
shorturl.at/gHPY9 (example result picture)
Tried to find a solution myself, but am stuck.
Best,
Feal
Use query() with a where clause, like this:
=query(
J15:J114,
"where J is not null
offset " & max(0, count(J15:J114) - 5),
0
)

Product co-purchasing or bundles given a product ID

I have a data(amazon co-purchasing product) in two columns with values as product ID. I would like to select values from 100 - 299, 300-399, 400-999 and others values and group them. I want to create a bundle or co-purchasing between product in one group with another eg. 100-299 and 300-399, 400-999 and 100-299. The original data has two columns with FromNode and ToNode. Below are few lines of the original data. Some values(product ID) appear under both columns.
FromNode ToNode
0 1
0 2
0 3
0 4
0 5
1 0
1 2
1 4
1 5
1 15
2 0
2 11
2 13
2 14
3 65
3 66
3 67
I am using
df[df[['FromNode', 'ToNode']].isin([100,101,102...299]).any(1)]
to pick the values in the range but it seems I have to list all the values in the isin argument. Is there an efficient way to just give the range 100-299 to the isin(100-299) to fetch the values. Should just combine both columns into one and use iloc to select the values. Any tips will help.

SPSS selection of same ID rows based on difference between rows

I have a dataset where I have rows of data for each ID. Each row reflects a different time each ID has accessed the website. I have also created a variable which tells me how many months there were between each visit. I want to select all the cases from time 1 to last time value for each ID if they have returned after at least 1 month. What do I do?
ID Time MonthSince
1 1 .
1 2 0
2 1 .
2 2 1
3 1 .
3 2 0
I would like the dataset to look as follows:
ID Time MonthSince Filter
1 1 . Not Selected
1 2 0 Not Selected
2 1 . Selected
2 2 1 Selected
3 1 . Not Selected
3 2 0 Not Selected
What I suggest is calculate the total number of months in MonthSince. If this total is zero, we know there wasn't more then a month before the last visit and we can filter these cases out:
aggregate outfile=* mode=addvariables/break=ID/TotMonths=sum(MonthSince).
select if TotMonths>0.

How to group by two columns

I'd tired group by week,day, it didn't give me the correct result
Here is the table: weekDay
week day
-----------
1 1
1 1
1 2
2 1
2 1
2 1
2 2
2 2
and expected result:
week day count
---------------------
1 1 2
1 2 1
2 1 3
2 2 2
How to get the result above by using group by or other ways?
Use following SQL query to retrieve result
SELECT week, day, count(wd.id) AS count FROM week_day wd GROUP BY wd.week, wd.day

Using sum when grouping one more columns in LINQ

I have 2 tables like below.
For comments to vote
VoteId VoteValue UserId CommentId DateAdded
1 1 1 1 10/11/2013
2 1 5 1 10/14/2013
3 1 9 2 09/08/2013
4 1 11 3 01/03/2014
For users that take point values
PointId Date PointValue UserId
1 10/11/2013 1 1
2 10/14/2013 1 5
3 09/08/2013 1 9
4 01/03/2014 1 11
I should find 10 users that most taken votes each month in all comments. Firstly I try to write LINQ like that;
var object = (db.Comments.
Where(c => c.ApplicationUser.Id == comment.ApplicationUser.Id).
FirstOrDefault()).ToList();
I can't use sum and add points to my table. Any helps?
I hope it's clear.
First you should extract mounth from datetime value, then group by month descending and also take sum of all coments and use Take(10) at the end.

Resources