Excel, getting values from the same row but different column - excel

I'm trying to write a GPA calculator in Excel (LibreOffice really, but it works the same) and what I need help with is calculating quality points. I've only ever coded in C and similar languages, so spreadsheets and their notation are incredibly foreign to me.
In case you don't know, GPA is calculated by dividing your total quality points by your total credit hours, quality points being your grade set to a 4-scale in a particular class multiplied by the class's credit value. So, for example, if I got an B in a 4-hour class, I would get 3*4 = 12 quality points for that class. If I took a 17-hour semester and earned 63 quality points, my GPA for that semester is 63/17 = 3.706.
Getting to the point, my spread sheet is set up something like this
A B C
GRADE CREDITS QUALITY
1 B 3 9
2 A 4 16
3 B 1 3
...
so my formula would look something like this
IF(A1="A",4*B1,
IF(A1="B",3*B1,
IF(A1="C",2*B1,
IF(A1="D", B1,0))))
The problem is, this code will only work for row one. For any other row, I'd have to replace all the 1s with the row number being calculated. There must be a better way to write this formula. How would I go about generalizing this so I can just copy and paste the formula without editing it?

In Excel you can copy and paste a formula, or fill-down a formula and it will automatically update the references for you. Have you tried copying the formula down? Otherwise you can do indirect formulas that use commands like INDIRECT and ROW, but I cannot guarantee those will convert to LibreOffice.
If you need to use INDIRECT formulas, it'd look something like this:
=IF(INDIRECT("A" & ROW())="A",4*INDIRECT("B" & ROW()),
IF(INDIRECT("A" & ROW())="B",3*INDIRECT("B" & ROW()),
IF(INDIRECT("A" & ROW())="C",2*INDIRECT("B" & ROW()),
IF(INDIRECT("A" & ROW())="D", INDIRECT("B" & ROW()),0))))

Related

Excel cell formula to count keys from one table, if their values in another table are a specific criteria

I feel like the answer to this one is simple, but I just can't seem to wrap my head around it: I have a large table of historical data (example on the right) of when specific part numbers are shipped out, and whether they are one of two categories (example on the left).
Part Type | Part Shipped Date Shipped
Part#1 W | Part#3 23-Apr
Part#2 W | Part#3 25-Apr
Part#3 W | Part#5 17-Apr
Part#4 U | Part#2 18-Apr
Part#5 W | Part#6 25-Apr
Part#6 U | Part#1 18-Apr
I'm trying to get a COUNTIFS formula to tally up all [Part Shipped] entries that were between [Last Monday] and [Last Friday], but only where the [Type] is of type "W". I've gotten the date criteria down, but I can't quite puzzle out how to pass the [Part Shipped] criteria range over to the other table in order to reference and count the [Type]
The input data is taken from a live data feed(Odata, atomsvc file), so I use full columns as criteria range such as 'DATA'!X:X.
I've figured out the date criteria as such:
">=" & ((TODAY() - 7) - (WEEKDAY(TODAY()) - 2))
"<=" & ((TODAY() - 7) + (WEEKDAY(TODAY()) - 6))
and my full formula so far is as such:
=COUNTIFS('SO Progress'!X:X, ">=" & ((TODAY() -7) - (WEEKDAY(TODAY()) -2)), 'SO Progress'!X:X, "<=" & ((TODAY()-7) + (WEEKDAY(TODAY())-6)))
but this doesn't have any criteria for counting the types yet. I thought about using a simple VLOOKUP and comparing it to "W", but my main problem is figuring out how to pass the full range into the VLOOKUP formula and get results back for each line in the range.
At this point, I feel like it's probably just a matter of me not knowing how one or more of these functions or tools can be used to get what I need, since I feel like this is probably a common sort of issue. I just can't seem to find any results specific enough to help my case.
[EDIT]
Using the above data, assuming that the columns are contiguous A:D, I'm looking to first filter dates shipped (D:D) that fall within last week Monday through Friday. For example, using today (4/29), that range would be 4/22 through 4/26.
This initial pair of criteria will get me three results: Part#3, Part#3 and Part#6. However, Part#6 is of type "U", illustrated by columns A and B, so my end result tally should wind up being 2.
The A:B table contains unique part numbers and their types for reference, but shipped parts in table C:D may be duplicates and will, in most cases, be much larger than the type reference table.
That took a while to figure out, but you can use the following array formula (use Ctrl+Shift+Enter and you should see braces in the formula bar if you did it right):
=SUMPRODUCT(--(D2:D7=TRANSPOSE(A2:A7))*TRANSPOSE(B2:B7=H2)*(E2:E7>=(Today-WEEKDAY(Today,2)-6))*(E2:E7<=(Today-WEEKDAY(Today,2)-2)))
I think it should work, I tried to play a bit with different values and it seemed to be holding up fine. In the above snapshot, Today is H1.
It will of course take a long time to calculate if your data sets are big, in which case, I would recommend doing the exercise in SQL which is more suited for this kind of operation (faster and simpler to do).
If you're looking to count occurrences where date is greater than x, AND date is less then Y, AND z = "W", then just add another criterion to your COUNTIFS() function.
The formula below assumes dates are in column D and type is in column B - obviously adjust these to suit your worksheets.
=COUNTIFS(D:D, ">=" &TODAY()-7-WEEKDAY(TODAY()-2),D:D, "<=" & TODAY()-7+WEEKDAY(TODAY()-6),B:B,"=W")

Using VLOOKUP to return information based on the maximum value in a range

I am trying to use vlookup to return information based on the maximum value of a cell within a range.
I have a table in which each row is a sports team and each column is a weekly points total.
I have 2 cells that show the highest points scored in the current week and the name of the team that scored them.
The team name is generated by the formula
=VLOOKUP(MAX(Admin!G3:G16),Admin!G3:K16, 5, FALSE)
This works fine.
I also wish to have 2 cells that show the highest weekly points total ever achieved, along with the name of the relevant team.
However, I can not amend the above formula to work on a range instead of a row, and no matter what I do, it always returns an #N/A result for the team name.
The most logical formula I tried is
=VLOOKUP(MAX(Admin!N18:BE31),Admin!N18:BG31, 47, FALSE)
where columns N through BE are the weekly scores (which are generated by a formula, if that makes a difference?) and column BG contains the team names.
Maybe this function isn't designed to work on a range in the same way as a column, maybe I have made an error in the formula, or maybe there is another better way to retrieve the information?
I just can't work it out, so am sincerely hoping somebody can point me in the right direction.
Many thanks for any assistance.
Indeed, the vlookup function works only with columns. So does the match function. You need here to use a formula array (hit "Ctrl + Shift + Enter" once you've typed the function instead of the usual "Enter").
I came to the following function
=INDEX($A$2:$A$9,SMALL(IF($B$2:$D$9=$H$2,MATCH($A$2:$A$9,$A$2:$A$9,0),""),1))
with :
1) $A$2:$A$9 = The teams
2) $B$2:$D$9 = The weekly scores
3) $H$2 = the maximal score ever achieved
You just need to adapt the ranges and hit "Ctrl + Shift + Enter"
PS: If 2 teams achieved this score, then only the first one will show

Excel Add up columns regardless of row

I have data like this in an excel sheet:
1 2 3
4 5 6
What I am trying to do is come up with a formal that will give me the total of each row, something like this =A+B+C, so I can use this formula on each row...I have plenty of rows, The above is just and example, I have this =A1+B1+C1 is there away in excel to get A1 + B1 + C1 without the row number?
Please help, this would save me lots of time.
I have looked into =ROW to get the row number, can I use the sum function with the row function?
=SUM(A=ROW():B=ROW())
I found a solution to my problem:
=SUM(INDIRECT("A"&ROW()):INDIRECT("C"&ROW()))
This will work
=SUM(INDIRECT("A"&ROW()):INDIRECT("C"&ROW()))

Different approach to my situation

on a excel sheet I've got columns, each column represents a weeknumber.
I want to calculate the so-called 4 wk average for each row and for each week and this is the formula I use:
((value*Tvalue)+(value*Tvalue)+(value*Tvalue)+(value*Tvalue))/(Tvalue) (this is not the actual formula but simplified, that's not really important).
It's the checks that make things a bit more complex. If a value of a weeknr is zero, skip it, but if the next value is also zero, just skip the formula alltogether and make it a zero (or text like "false"). So another thing that has to be accounted for is that if a value is zero, the next weeks value is taken instead.
Example (see included file):
I want to calculate the formula (mov 4wk avg) for the third value for week 12, which will make the formula (0.2*6)+(0.3*6) now there's a zero on week 14 so I skip it, then formula will be:
(0.2*6)+(0.3*6)+(0.6*6)+(0.9*6)/(6). Hope that made some sense.
Right now I'm doing this in VBA with a lot of variables and a lot of if statements.
Is there an easier more effective way to go about this?
Example sheet
https://dl.dropbox.com/u/3121767/Book1.xlsx
PS I know the example sheet is a 2007/2010 version but I need to accomplish this for 2003
Array formula could be used (Ctrl-Shift-Enter in formula window, curled brackets will be inserted by Excel itself, not by a user):
A3: T value for row 3
B3:E3: values for single weeks in row 3
={IF(OR(SUM(IF((B3:C3)=0;1;0))>1;SUM(IF((C3:D3)=0;1;0))>1;SUM(IF((D3:E3)=0;1;0))>1);"Fail";(B3*$A3+C3*$A3+D3*$A3+E3*$A3)/$A3)}
The formula takes pairs of weeks, if the sum of the pair is 0, the whole formula will fail. If there's only one zero, everything will remain the same, as 0*value is equal to skip.
The formula can be copied to the right and downwards.
The updated exampe is available at http://www.bumpclub.ee/~jyri_r/Excel/4_week_average.xls
I tried a 2-step approach
1) transform each cell according to following rules:
if myweek = 0 and mynextweek = 0 then
myweek = 0
elseif myweek = 0 and mynextweek <> 0 then
myweek = mynextweek
else
myweek = myweek
endif
in Sheet2!B2 I entered =IF(AND(Sheet1!B2=0,Sheet1!C2=0),0,IF(Sheet1!B2=0,Sheet1!C2,Sheet1!B2)) and copied to all cells where in Sheet1 dat aexists, together with a copy of the base value in column A
2) Then I create a standard moving average across 4 weeks, for each set of 4 columns, starting with W15 in column M ... matter of taste if you display this in Sheet1 or Sheet2

Excel Problems- Calculated value as a cell reference

I'm relatively new to excel programming. I'm working on making a spread sheet that shows exponential decay. I have one column (A1:A1000) of 1000 random numbers between 1 & 10 using the TRUNC(RAND()*10,0) in each cell. The next Column (B1:B1000) has a logic mask =IF(A1=0,1,0) , where if the value in the A cell is 0, then the B cell shows a 1. Next, to find the number of 0's in the A column, I have the next column taking the sum of B1:B1000, which returns the number of 0's that showed up in the first column. I'm sure there's an easier way to do that, but this seems to work fine.
Here's my problem, hopefully it's clear what I'm asking:
Next, I want to take the sum of the logic column (B) from B1:B(1000- the value of the sum from (B1:1000)) in the cell below the cell that calculates sum(B1:B1000). Is there a way to to algebra in a cell formula to reference a cell? More simply, if I want to refer to A3, for example, is there a way to input something like A(2+1) to get A3? Does this make sense?
You can very easily do, in VBA:
ActiveCell.Formula = "=A" & (2+1) & "+15"
In Excel:
=INDIRECT(ADDRESS(2+1, COLUMN(A1)))+15
This will set the formula to "=A3+15". Generally, this is best done with variables, so remember to do that.
In Excel, and as pointed out by Eric, you can write the referance to the cells just like normal strings thanks to INDIRECT() function.
Just make sure that the string passed to INDIRECT() is a valid cell reference.
For example :
=SUM(INDIRECT("B" & 2+7*(H2-1)):INDIRECT("B"&(2+7*H2)-1))
Here, I sum 7 lines for each week (H2). It gives the sum of B2:B8, B9:B15, B16:B22, etc.
Hope my example will help you figure out how to use it in real situation.

Resources