Combine variables by adding rows - spss

I have different columns of contentious variables and each column represents a category. I would like to combine all columns into a single column by adding the appropriate number of rows and create a new column for the category name of each row using spss or excel.
This is what my data looks like now:
This is what I want to have:

This is a simple restructure, use varstocases like this:
varstocases make value from A B C/index=category(value).

Related

Google Sheets: Many to Many Table Join

I am trying to create a sheet to determine the amount of overlapping hours for employees.
I have one table with timeclock data for the Employees.
Table 1
And another with timeclock data for their Support Staff.
Table 2
This is the desired output. Each row from table A has all the date matches from table B. From here I would compute the number of overlapping hours in the final column and then roll that up into another sheet.
Table 3, Desired Output
(apologies for image links, I can't post inline images yet)
Sample sheet here Please let me know if you have any ideas for me!
I know its a combination of QUERY, ARRAYFORMULA, FILTER and more but I just can't find the right combo.
Here's a way of doing this type of join using only built-in functions:
=arrayformula(lambda(employee,support,
lambda(datecomp,
lambda(rows,
{vlookup(index(rows,,1),{row(employee),employee},sequence(1,columns(employee),2),false),
vlookup(index(rows,,2),{row(support),support},sequence(1,columns(support),2),false)})(
split(filter(datecomp,datecomp<>""),"|")))(
flatten(if(index(employee,,1)=transpose(index(support,,1)),row(employee)&"|"&transpose(row(support)),))))(
Employee!A1:D6,Support!A1:E5))
There's a lot going on here, but the basic idea is that we are comparing the date columns of each table against each other in a 2D IF array, and where the dates match we are obtaining the row index of each table. After some manipulations we can use these row indexes on each table in two side-by-side VLOOKUPs to obtain the joined table.
DMac,
I wrote myself a QUERY replacement custom function that uses real SQL select syntax.
For your data it looks something like (You need a tab called employee and a tab called support for this to work) :
=gsSQL("select * from employee full join support on employee.date = support.date")
See my test worksheet: (line 164 on gsSqlTest sheet)
https://docs.google.com/spreadsheets/d/1Zmyk7a7u0xvICrxen-c0CdpssrLTkHwYx6XL00Tb1ws/edit?usp=sharing
You need to add one Apps Script file to your sheet to give you the custom function:
https://github.com/demmings/gsSQL/blob/main/dist/gssql.js
For more help using more features see:
https://github.com/demmings/gsSQL
For example, changing the column titles, it would be like:
select employee.name as name .... (rest of your select).

How do you sum table by columns and return range of sums?

I have a table Elements/Objects where columns are elements and rows are objects which can be crafted from the combination of elements. Cell contain how much of specified element is required for the object. It looks like that:
Another table, called Packs contains the list of packs. Each pack contains one or more objects. It looks like that:
What I need to do is append packs into my first table of Elements/Objects. Every pack there should be a sum of elements required for every object of a pack. So it need to look like that:
What formula should I use for cells with Pack 1 and Pack 2?
You can use IFs:
=IFS($A4="Pack 1",B$1+B$3,$A4="Pack 2",B$2+B$3 )

Google Spreasheet: get unique values from two columns into a single one

I need to get unique values from two columns into a single one.
I tried with formula unique(A:B) but this formula creates two columns for the results. I need the results to be in a single column. Take a look at my capture:
You could try (in D3):
=unique({A3:A;B3:B})
The braces with the semicolon create a stacked column of A and B.
To avoid blanks, you could try:
=filter(unique({A3:A;B3:B}), unique({A3:A;B3:B})>"")

Locking Columns in Google Sheets when a cell reaches a number

I am creating a spreadsheet to be used among 40 teachers to assign students to a variety of classes. Student names are in rows while the classes are in columns. As students join a class, there is a cell in the column that adds the total number of students who have joined the class. When the class reaches a specific number, I would like the column to change colors to indicate the class is full or completely lock the column so no more students may be added. Can anyone help?
Richard, if you just want to colour the column, you could try conditional formatting like so:
Pick the range of columns you want to be colour coded
Apply the custom formula =B$1>3. This means that for each column in the range, the formula will look at the first row in that column - that is why the $ is in front of the row number and not the column letter - and if that number is greater than 3 (class capacity), then the column will turn red(ish).
But if you want to lock the column, you'll need to get into Google Apps Script.

How to get only the Surname in a range of cells?

I have a spreadsheet having a column of names. Now, in another sheet I want to have the surnames from the aforementioned column to be displayed in a dropdown. How can I do this?
The names look like this:
Surname, FirstName
And there are also people from the same household having the same surnames. There are no people with the same surname that belong to different households. So I kind of want to get the surnames to identify that household.
You can create a single array formula referencing that list of names, that only pulls the surname portion using regexextract like this:
=IFERROR(UNIQUE(ARRAYFORMULA(REGEXEXTRACT(A:A,"^(.*),"))))
To explain, the regexextract, I feel is a lighter formula and slightly simpler than using a split function for two reasons:
A split function would require you put both names to two separate cells, and unfortunately split function does not work with arrayformula.
But since regex does - the regex I specified is basically saying grab any text (.*) from the beginning of the cell ^ up until that comma ,.
I then wrap the whole function in unique, so you dont have to deal with a ton of duplicates in your dropdown.
Following that I used Data Validation to point to the range of these unique surnames.
And just for fun at the end I finalized it with a FILTER function that would populate all the corresponding cells based on the surname chosen from the dropdown using this formula:
=FILTER(A:A,REGEXMATCH(A:A,C1)=TRUE)
To wrap all this information up, here is a sample image of what it looks like in the end:
I guess you have to split the names into another column. Let's say your names column is in A1, set the following formula in B1 and copy it in the next cells of the B row :
=SPLIT(A1;",")
Then, you can define your dropdown list in another sheet as explained here : https://support.google.com/docs/answer/186103

Resources