Weighted lottery [duplicate] - google-sheets

This question already has answers here:
Repeat whole row N times based on column value in Google Sheets
(2 answers)
How to Repeat a Data Set (several columns) x times in Google Sheets [duplicate]
(1 answer)
Repeat range of items multiple times in Google Sheets
(5 answers)
Closed 5 months ago.
I need to create a weighted lottery where people can have multiple entries and the number of entries is based upon a series of questions. For each question they get right, they get an entry into the lottery.
In my head, I've got a table with the participants' names and their total number of points (entries), then I need some way to have a list of the names with their multiple entries. So if my initial table looked like this:
Name
Points
John
5
Larry
4
Andre
2
Mika
6
Then my output list would look like this:
Name
John
John
John
John
John
Larry
Larry
Larry
Larry
Andre
Andre
Mika
Mika
Mika
Mika
Mika
Mika
Then I could just use the default row leaders from the output table as the entry for the person and use a random number generator to pick numbers.
That being said, I'm open to other ideas.

Try this formula-
=QUERY(INDEX(FLATTEN(SPLIT(REPT(A1:A4&"#",B1:B4),"#"))),"where Col1 is not null")
REPT(A1:A4&"#",B1:B4) will repeat each cell value of A1:A4 as per number in B1:B4. Then Split and flatten with make them a vertical array (column). Query() will return all the values except nulls (if any).
To make it more dynamic you may try-
=QUERY(INDEX(FLATTEN(SPLIT(REPT(A1:INDEX(A1:A,COUNTA(A1:A))&"#",B1:INDEX(B1:B,COUNTA(A1:A))),"#"))),"where Col1 is not null")
And with new LAMBDA() functions.
=FLATTEN(SPLIT(JOIN("",BYROW(A1:INDEX(B1:B,COUNTA(A1:A)),LAMBDA(x,REPT(INDEX(x,1,1)&"|",INDEX(x,1,2))))),"|"))

Related

Repeate filled cells of a row for x times in another row in Goolge Sheets by formula [duplicate]

This question already has answers here:
Repeat range dynamically
(2 answers)
Closed 15 days ago.
I have a column containing x rows of names and I want to be able to repeat those rows of names x times each in another row.
It should be possilbe to have at least 15 names and repeate it 900 times.
Here an example:
I tried this now for about 6 hour with arrayformula etc. and didn't find any working solution..
For example =TRANSPOSE(split(rept(join(";",A:A)&";",10),";")) would do the job, but the rept function is limited in characters, so it doesn't work for this case..
Are you able to do this?
You can try with REDUCE and SEQUENCE like this. It's wrapped in QUERY to exclude empty rows, so you can get your full column as input, despite its amount of elements:
=QUERY(REDUCE(,SEQUENCE(A1),LAMBDA(a,v,{a;B1:B})),"Where Col1 is not null")
use:
=INDEX(FLATTEN(TEXT(TRANSPOSE(A1:A4); FLATTEN(SPLIT(REPT("#×"; 5); "×")))))

Repeat A1:A4 n times [duplicate]

This question already has answers here:
Repeat range of items multiple times in Google Sheets
(5 answers)
Repeat whole row N times based on column value in Google Sheets
(2 answers)
Repeat each row N times in Google Sheets
(4 answers)
Closed 5 months ago.
I've searched and cant find the answer to this seemingly easy task
I'm looking to repeat A1:A4 n times
A1:A4=
California
Off
Texas
Off
Desired output: n=4
California
Off
Texas
Off
California
Off
Texas
Off
California
Off
Texas
Off
California
Off
Texas
Off
There are multiple ways to repeat text in columns:
Solution 1:
=FLATTEN(TRANSPOSE(ARRAYFORMULA(SPLIT(REPT(A1:A4&";",B1),";"))))
Where B1 is the number of the repetition.
Solution 2:
You may also use Join
=transpose(split(rept(join(",",A1:A4)&",",4),","))
Solution 3:
You can also use TextJoin
=FLATTEN(split(REPT(TEXTJOIN("^",TRUE,(A2:A),"^"),B2),"\^"))
Result:
try:
=INDEX(FLATTEN(TEXT(TRANSPOSE(A1:A4); FLATTEN(SPLIT(REPT("#×"; 4); "×")))))
or see: https://stackoverflow.com/a/54266697/5632629

How to apply =ARRAYFORMULA() to create a reversed numbered list in Google Sheets?

The formula has to be input on cell A2. The logic should be that the formula would result in the following cell (from cell A3 downwards) outputting a no. in a reversed numbered list format in column 1. And for those who are "Resigned" or "Dismissed" in column 3, the formula would skip them and the next numbering would be a follow-up from the previous no. instead.
We're using in-house software that's similar to Google Sheets and Microsoft Excel so certain functions/formulas like REGEX and custom functions are not supported.
No.
Name
Employment status
(insert formula here
Sample Name
Type of Employment
5
John
Full-time
Mary
Resigned
4
Jack
Part-time
3
Tim
Contract
Jane
Dismissed
2
Jonathan
Full-time
1
Larry
Part-time
This post is a repost from this ask as the solutions weren't applicable to this issue, unfortunately. So I'm looking for alternative solutions from those answers.
Alternative:
=ARRAYFORMULA(IF(MMULT(N(C2:C8={"Resigned","Dismissed"}),{1;1}),"",MMULT(N(ROW(C2:C8)<=TRANSPOSE(ROW(C2:C8))),1-ISNUMBER(MATCH(C2:C8,{"Resigned","Dismissed"},0)))))
Note that the oft-seen technique of replacing the upper cell reference in the range passed with a reference to the entire column (for example, C2:C) would here not be advisable. If such flexibility is required, suggest you create a dynamic Named Range.
can't be simpler:
=ARRAYFORMULA(IF((C2:C="contract")+(C2:C="part-time")+(C2:C="full-time"),
COUNTIFS(SUBSTITUTE(C2:C, "Contract", "time"), "*time", ROW(C2:C), ">="&ROW(C2:C)), ))
Paste this formula in A2
= {"Count" ; ArrayFormula(IFNA(IF(B3:B="",,VLOOKUP(B3:B, FILTER({ B3:C, SEQUENCE(ROWS(B3:B),1,COUNTA(B3:B),-1) }, C3:C<>"Resigned",C3:C<>"Dismissed"),3,0)),""))}

Total Sum With Vlookup

I have two spreadsheets with names and times. One is specific session times and on the second sheet, I want to sum up the total times based on each instance from sheet one.
Sheet 1: Session Time
Name | Time
David 5
Mike 2
Daniel 3
David 2
Daniel 8
Sheet 2: Total Time (The one for which I need a forumula)
Name | Total Time
David 7
Mike 2
Daniel 11
I tried a countif and vlookup but I couldn't get it match more than one instance of the name on sheet 1. I also tried this suggested formual from a suggested post but its not summing a second instance of the user name
=ARRAYFORMULA(SUM(ifna(VLOOKUP(A2, 'Sheet 1'!A3:AA16, 5, false))))
A2 = David (On Sheet 2)
Sheet 1'!A3:AA16 = List of names in columns A and all the way to AA is a series of columns with numerical values
5 = the column number from with I want to return the sum for every instance of David (2 in this example with a total of 7)
False = its not sorted
Any help is mucho appriciado!
You can use this formula in your Sheet2!B1:
={"Total Time";arrayformula(if(A2:A<>"",sumif(Sheet1!A1:A,A2:A,Sheet1!B1:B),""))}
Or simply use =arrayformula(if(A2:A<>"",sumif(Sheet1!A1:A,A2:A,Sheet1!B1:B),"")) in Sheet2!B2
Get the sum of the range based on a specific criteria using SUMIF()
Basically, get the sum of Sheet1!B1:B if Sheet1!A1:A matches the current cell being checked in arrayformula A2:A
Output:
This can be accomplished with a simple QUERY, e.g.,
=QUERY('Session Time'!A:B, "Select A, SUM(B) WHERE A Is Not Null GROUP BY A LABEL SUM(B) 'Total Time'")

Sum / Counting items in a column that match 3 criteria

Thank you ahead of time for anyone who can help me with this, I think I am close, but it still isn't working.
I have a simple sheet activity reporting sheet that I am asking staff to complete over the upcoming year - It has 5 columns:
Column A: Date -In format (4/4/2013 13:30:00)
Column B: Title -In format (text string)
Column C: Attendance -In format (Numbers)V
Column D: Vol led - In format (text string)
Column E: Staff Led - In format (text string)
Using this data I am 90 % positive that I can aggregate on a different summary sheet that contains some static data like months (in the B column) to aggregate on. I am having trouble configuring the criteria in the filters though to cause the correct output to either sum or count .
Quantity of events ed by either staff or vol, if neither box is checked the event should not be counted) Right now I am trying this but it is not working
=SUM(FILTER('Hostel Activities'!A:A,MONTH('Hostel Activities'!A:A)=$B3, NOT(AND(ISBLANK('Hostel Activities'!D:D),ISBLANK('Hostel Activities'!E:E)))
Total number of attendance in a month for activities led by staff or volunteers Right now I am trying this but it is not working
=SUM(FILTER('Hostel Activities'!A:A,MONTH('Hostel Activities'!A:A)=$B3, NOT(AND(ISBLANK('Hostel Activities'!D:D),ISBLANK('Hostel Activities'!E:E)))
THIE WORKS! ## Heading ##Total number of volunteer led activities in a month for activities Right now I am using this and it IS working
=COUNT(FILTER('Hostel Activities'!A:A,month('Hostel Activities'!A:A)=B3,not(isblank('Hostel Activities'!E:E))))
Thank you for any assistance and/or guidance
Danny
The first problem I see with your first two formulas is that you're calling SUM on your FILTER result. But the FILTER is returning the column A, which are dates. So, your basically summing dates, which will surely not yield the result you're looking for. Why are you not using COUNT, as you did on your last formula?
Second, the first two formulas you pasted are identical, how do you expect them to return different results?
It seems that for the first two want to sum an OR condition. You can do this two ways (that I can think of now). The simpler to understand is just to sum two COUNT(FILTER(... formulas, one for each criteria, e.g.
=COUNT(FILTER('Hostel Activities'!A:A,month('Hostel Activities'!A:A)=B3,not(isblank('Hostel Activities'!D:D)))) + B6
Assuming that on B6 is the other COUNT formula (the 3rd one, that already works).
Another option would be to use an OR function as criteria for the FILTER. Like this:
=COUNT(FILTER('Hostel Activities'!A:A,month('Hostel Activities'!A:A)=B3, OR(NOT(ISBLANK('Hostel Activities'!E:E)), NOT(ISBLANK('Hostel Activities1!D:D))) ))
I believe I have figured out a method that works by making some adjustments in the formulas and the source data.
Basically
IN THE SOURCE REPORTING DATA:
I combined columns D and E into the same column and added data validation so the coordinator has to enter if the activity is led by staff,volunteer, or neither.
IN THE MONTHLY AGGREGATION REPORT:
To count the number of activities led by either staff or volunteers I used this :
=COUNT(FILTER('Hostel Activities'!A:A,month('Hostel Activities'!A:A)=B3,'Hostel Activities'!D:D="Staff"))+E3
*E3 is the count of volunteer led activities which is found using this formula:
=COUNT(FILTER('Hostel Activities'!A:A,month('Hostel Activities'!A:A)=B3,'Hostel Activities'!D:D="Volunteer"))
Adding up the number of participants in activities run by either staff or volunteers was a little more difficult, but I was able to do it by adding up 2 unique equations. I would prefer using an OR statement in the filter criteria, but I just couldn't get that to work. This is how I was able to make it happen:
=SUM(FILTER('Hostel Activities'!C:C,month('Hostel Activities'!A:A)=B3,'Hostel Activities'!D:D="Staff")) + SUM(FILTER('Hostel Activities'!C:C,month('Hostel Activities'!A:A)=B3,'Hostel Activities'!D:D="Volunteer"))
Thank you all for your assistance

Resources