how to specify the first cell with data in it inside an if statement in Excel - excel

I keep a running avg of kids grades in Excel over a 2 week period. The way i have the code now
AVERAGE(OFFSET('1'!E4,COUNTA('1'!D:D)-29,):OFFSET('1'!E4,COUNTA('1'!D:D),))
it returns an error if i don't have 2 weeks of data. I found a way around this by doing this
=IFERROR(AVERAGE(OFFSET('1'!E4,COUNTA('1'!D:D)-29,):OFFSET('1'!E4,COUNTA('1'!D:D),)),IFERROR(AVERAGE(OFFSET('1'!E4,COUNTA('1'!D:D)-28,):OFFSET('1'!E4,COUNTA('1'!D:D),)),IFERROR(AVERAGE(OFFSET('1'!E4,COUNTA('1'!D:D)-27,....
Im Sure there is a better way to do this any help would be appreciated.

As pointed out in the comments - it's difficult to give a definitive answer without some more knowledge - it's not easy to tell, for instance, where the numeric data starts (E4 or E5)?
Firstly you can simplify your original formula which appears to AVERAGE the last 30 rows of data (not sure how 30 rows equates to 2 weeks of data) - you can do that with just:
=AVERAGE(OFFSET('1'!E4,COUNTA('1'!D:D)-29,0,30))
Now I assume the error comes about when COUNTA('1'!D:D) is < 29 so you can simply add an If function which AVERAGES all the data if that function returns a number < 29, i.e.
=IF(COUNTA('1'!D:D)<29,AVERAGE('1'!E4:E33),AVERAGE(OFFSET('1'!E4,COUNTA('1'!D:D)-29,0,30)))
That formula may need some small adjustments to cater for the specifics of your layout but the general approach is valid

Related

Using IF with ROUNDDOWN, To Calculate How Many Times For A Process

I apologize if the title is a bit vague. I am trying to create a calculator that takes into account how much "scrap" I have, how much is needed to resmelt it, and how many bars recieved.
Currently using:
(=if((amtOwned/qtyToSmelt)<1,,rounddown((amtOwned/qtyToSmelt)*barsMade))
Table and Formula
The problem I am having is you MUST have the QTY to Smelt. But the value returned includes partial quantities.
Ex. 125 Bottle Caps should equal 4 Bars total. Yet it returns 5.
How can i make the formula only account for increments of the bars recieved?
Thank you for any help, again i apologize if this isn't that clear. Im not exactly sure how to express my need in this situation.
I have tried messing around with the syntax and where every argument sits, even this formula is the most recent iteration of what i thought would be needed.
EDIT: I have tried using the TRUNC function and this seems to be working as I need it to. The formula now is:
=TRUNC((AMTowned/AMTneeded),0)*barsRecieved
=TRUNC((136/50),0)*2 This is returning 2 bars instead of 3. Which is exactly what I need.
It appears this is working by truncating the number first then multiplying it. So, 1.5 becomes 1 before being multiplied. This was my guess after doing more research. I had been searching for a while before I posted this but am glad to have learned what I have in searching for this.
There is a tool for auditing formulas. To see it go to Formulas > Evaluate Formula.
So here is you formula =IF((E3/C3)<1,,ROUNDDOWN((E3/C3)*D3,0))
Have you tried the calculation on your regular calculator? To me it is doing what you would expect. (125/50)*2 = 5

Subtracting times across a day in excel

I am working on the capstone project in of the Google Career Certificate in Data Analytics. I am using Microsoft Excel. I have to calculate the ride length based on the start and end ride times. I've inputted the formula =F2(end time)-D2(start time) which returns the ride length. Going through my entire list I have some areas where the start time is like 11pm and the end time is 1am and this is returning ###### because it is a negative number with the regular formula. I've found a modified formula that can kind of do the conversion I am looking for but it is still a bit problematic. The modified formula is =(F2-D2+(F2<D2))*24 and it seems to give an accurate ride length if I reformat the answer to number. The issue is the rest of my data is in time format and the modified ones are in number format. If I convert the number values to time, the ride length values are inaccurate.
It is tricky to make the numeric value change as well due to me using a formula. I can correct them one by one after I save Excel and it no longer stores the numbers as the formula, but there are lots of data points to change and that would be time consuming. I'm hoping to find a more concise way to solve this problem. Maybe with a better formula.
[Snippet of the chart 1
Just like everything in life, there are multiple ways to achieve things. I would have formatted the date and time into a single cell; but. if you're gathering the data from another source, that's understandable.
A simple IF statement here will work. IF the days are one apart, then take '1' day off the starting time, else do your original formula:
=IF(E4-C4=1,F4-(D4-1),F4-D4)

Using Sumproduct to calculate two tables using horizontal (table headers) and vertical references

Hopefully the title makes some sense because I'm trying to wrap my head around the logic and I'm not quite sure how to phrase the question.I'll try to give a brief explanation of the end goal without over complicating it with unnecessary details.
I have a table of survey score averages for every month per person and a correlating table with the number of surveys each person received for each month. The logic is essentially multiple the score for each month by the number of surveys, combine them, divide by the total number of surveys within that time period to get their true average. Where things get a little complicated is that I have to include the ability to set a custom date range and return the value. So sometimes I might be looking at the average for Jan - Apr, other times I might just be looking at Feb-Mar etc.
I think sumproduct is going to get what I need done but I'm running into issues trying to write it out. I've written it several different ways and none of them worked so here's one that best conveys what I'm trying to do,
=SUMPRODUCT(--(F7:I7,L7:O7>=C2),--(F7:I7,L7:O7<=C3),--(E8:E12,K8:K12=B9),tbl_average[[Jan-20]:[Apr-20]],tbl_surveys[[Jan-20]:[Apr-20]])
I super appreciate any assistance I can get on this. I'm hoping the end result is not nearly as difficult as I'm making it out to be.
Some additional information:
I'm going to be using this same process to calculate multiple metrics across multiple worksheets.In the test example each of the tables will most likely be on different sheets. The dashboard with the calculated results will contain everyone's names and will be filtered and rearranged frequently, so I need to make sure we're always matching directly to their names and not just the relative rows. Basically, in my example I show that Agent 1 is always lined up on row 8 but that's not always going to be the case. Agent 1 could be in Row 8 on Sheet 1, Row 10 on Sheet 2, and Row 12 on Sheet 3 and I need all the correct values to multiply and sum against one another.

How to filter data of last record of each week

I have a big data set of daily selling value of a particular ITEM. I want to know what was the price of ITEM on the last day of each week. Typically the last working day is Friday but if you don't have data for Friday then we need to get the previous working day data (Thursday).
Monday is considered the First day of week.
My Data looks something like this:
Data is in cells A2:C13.
My expected output is shown below:
Please help with VB macro or even simple excel formula.
You may want to try using a formula using the LOOKUP function, to search the list from bottom to top.
Afterward, a combination of INDEX and MATCH may get you on the right path as well.
Edit: I realize now that I was leading you astray because I thought you were asking something else! The most straightforward way I can see is as follows:
use WEEKDAY() to pull out the weekday values (as you did), except leave the values as numbers (with 1 being Sunday and 7 being Saturday).
Check each of these days to see if it precedes (i.e. has a lesser value) than the day above it. If not, we know that the week started over, and that cell is the last day of the week. Therefore, display its value.
Of course, this assumes that there are no Saturdays in your data - otherwise, Saturday would be listed as the end of the week. If you're crafty you can fix this dilemma though!
Thanks, Tyler.
Your suggestion helped me a lot in putting efforts in the right direction.
The way I did is as follows:
First I sorted my data in decreasing order of date so that I can have all the latest data at the top.
Range("AW4:BE999999").Sort Key1:=Range("BC4:BC999999"), order1:=xlDescending, Header:=xlYes
From Date created a string of "YEAR"&"WEEKNUM". This way I was able to group all the days in a specific week. Formula Used is:
=(TEXT(BC5,"yyyy"))&(TEXT(WEEKNUM(BC5),"00"))
Then I gave a unique Number to each record. The best way I could think of is to give the row number where record belongs.
=ROW(AY5)
Now using VLOOKUP function I got all the records matching string I have created in step 2
=VLOOKUP(AZ5,AZ:BD,5,FALSE)
I applied the above formula to get all the columns that I need.
Now I removed all the duplicate rows using below formula:
Cells.RemoveDuplicates Columns:=Array(1)
Now the remaining rows are the expected rows.
There may be a better way to do this but this is my first time with excel macro and formulas, so feeling happy.
Please comment other better ways to do this. It's always good to keep on improving our work.

Converting TEXT that represents NEGATIVE TIME value to a number or time value for adding (Excel)

I've got a spreadsheet (Office 2007 version of Excel) full of text entries that are negative time values, example "-0:07" as in an employee took 7 mins less to complete a job than expected. I need to perform mathematical calculations on these entries and am looking for a more elegant formula/method than I've come up with so far.
I know about 1904 date system and * or / by 24 to convert back and forth, the problem is getting a formula that will recognize the text entry as a negative time value.
I've tried value(), *1, which both work on the text fields if the number is positive, but the "-" seems to mess those up. Even paste-special/add fails to recognize these as numbers.
Here's what I came up with that gets the job done, but it's just so ugly to me:
=IF(LEFT(E5,1)="-",((VALUE(RIGHT(E5,LEN(E5)-1)))*-1.0),VALUE(E5))
Obviously my text entry is in cell E5 in this example.
This works, so I'm not desperate for a solution, but for educational purposes (and smaller code) I'd like to know if there's a better way to this. Does anyone have a suggestion for something shorter, easier?
Thanks.
P.S. - an interesting tidbit here, I use Excel at work, but not at home, so I uploaded a sample spreadsheet to Google Docs, and it actually handles the Value() command on those entries properly. Weird, huh?
Thanks again for any suggestions.
Excel doesn't handle time spans in cells. It only deals with time. When you do "00:07" it is then converted to 0.0048611 which is the same as Jan 1st 1900 12.07 am. So if you did 2 minutes minus 7 minutes it would give at best 11.55pm.
The way you do it is the only way.

Resources