sumif range and criteria switching - excel

So I have a table of number of fiscal weeks in a year, and to calculate depreciation I'm trying to sum the number of weeks in the total life of the capital investment. So the first argument is the range, the second argument pulls the year from another cell, and then adds the expected life in years of the device. The third argument is the intended sum range.
SUMIF(YearWeeks[Year],"<="&LEFT(AS$14,4)+$H20,YearWeeks[Weeks])
This works fine. Pulls in the right numbers no problem.
However, whenever I try and drag this across other cells so that it can be used throughout my spreadsheet to caculate depreciation, it immediately switches the value for year and the value for weeks and becomes:
SUMIF(YearWeeks[Weeks],"<="&LEFT(AU$14,4)+$H20,YearWeeks[Year])
I cannot figure out why it is doing this. It is probably something simple, but it is completely evading me. Any help would be greatly appreciated.
Year Weeks
2015 52
2016 53
2017 52
2018 52
2019 52
2020 52
2021 53
2022 52
2023 52
2024 52
2025 52
2026 52
2027 53
2028 52
2029 52
2030 52
Life
5
5
5
5
5
5
5
5
8
8
8
8
8
8
201504 201505 201506 201507 201508 201509 201510 201511 201512 201601 201602 201603

Instead of dragging the formula to the right, copy the cell and paste it in the cell at the right of it, etc... :
This will keep the column references unchanged (no change from YearWeeks[Weeks] to YearWeeks[Year]).
As specified on Microsoft's support website:
Moving, copying, and filling structured references
All structured references remain the same when you copy or move a formula that uses a structured reference.
When you fill a formula, fully qualified structured references can adjust the column specifiers like a series as summarized in the following table.
NB: YearWeeks[Weeks] is a structured reference, and fill is what many would call drag in this context.

Related

Excel DATEDIF not showing the correct answer

I'm trying to make a calculator that calculates the amount of years, months and days from one date to another. The problem is that the calculation of days not always is accurate, or at least I don't think it is. I have downloaded four age calculators from GooglePlay store, and two of them sometimes give me a different result.
When I use the dates as shown in the picture some of the two of the calculators give me the answer 6 years, 8 months and 9 days.
The formulas I use is as follow:
C4 =DATEDIF(DATE(C3;E3;F3);DATE(C2;E2;F2);"Y")
E4 =DATEDIF(DATE(C3;E3;F3);DATE(C2;E2;F2);"ym")
F4 =DATEDIF(DATE(C3;E3;F3);DATE(C2;E2;F2);"md")
Is there a way to figure out if my calculation is correct?
Clearly on 22 April 2019 they would be exactly 6 years 0 months 0 days.Also 22 December 2019 they would be exactly 6 years 8 months 0 days. Starting from there:
Based on inspection the value of 10 days appears correct.

Trying to create 2 columns out of 1 column of data using offset and indirect

Need to take 1 column of data and create 2 columns for maximizing the amount of data on each sheet.
Ive been working with offset and indirect formulas but not getting the expected results. Below are just a few examples of what ive tried and worked with and tried changing to get what i think i should be getting.
=IF(OFFSET(Sheet1!$A$1,(COLUMN()-1)*10+ROW()-1,0)="","",OFFSET(Sheet1!$A$1,(COLUMN()-1)*310+ROW()-1,0))
=OFFSET($A$1,ROW()*1-2+COLUMN(),0)&""
=INDIRECT("a"&ROW()*1-(2-COLUMN()))
So we have a need to create a excel template as dynamic as possible with as little printed pages as we can. Because the number of rows is unknown, we want to build the template in a fashion that allows for as little or as much data as we receive and need printed. So we have a need to fit 2 column sets per page, each set containing 10 rows each so we can have a total of 20 sets per page.
After finding offset and indirect, i started to work with that and see if i can create a formulas that would give me what we need..
What we are trying to see by using these formulas(if they are the correct ones to use) is the following:
Say we have 25 rows in our datasheet. We would like to see the following on our template.
Page 1
1 11
2 12
3 13
4 14
5 15
6 16
7 17
8 18
9 19
10 20
Page 2
21
22
23
24
25
Do not use INDIRECT and OFFSET if possible (And I have only found rare times they are needed) as they are volatile functions. Index is the best option:
Page1 put this in the first cell, copy over one and down ten:
=INDEX(Sheet1!$A:$A,Row(1:1)+((column(A:A)-1)*10))
In each sequential sheet add a factor of 20:
=INDEX(Sheet1!$A:$A,Row(1:1)+((column(A:A)-1)*10)+(20*1))
Change the *1 to *2 for the third and so on.

Finding MTD, QTD, and YTD in excel from monthly returns

I've been working on this for awhile and can't seem to find an appropriate way to code this.
Goal: Take a list of monthly returns that currently spans over three years (this is an automated list so it will keep adding months) and find MTD, QTD, & YTD using function so I can automate the process.
Problem: I've tried the OFFSET function, different versions of COUNT, IF statements and can't find a way to properly code the function.
NOTE: this is for stock data/earnings report
Just to clarify, I know how to do this manually, but want to automate the process :) Would be more than happy to use VBA but would like to stick to a simple function if possible...
I'd be more than happy to email the WS to someone. Thanks so much!!
If you want to keep it simple and avoid vba here is a suggestion
The manner in which the data sheet is presented matters.
I assume months go down, with there only being 1 column for 'monthly returns'?
On a separate area/worksheet, set up the months with a value for what they are in the column next to them. Ie
Jan 1
Feb 2
Mar 3
Apr 4
...
Dec 12
then have a drop down where you can select what month it is.
so if it is Jul, you can select Jul.
From here, do a vlookup/indexmatch to pull the number for the month through, so Jul would be 7
From here the MTD is easy.
Do an offset from the beginning of the year to the current month
=offset ([start point],[month number],[columns])
=OFFSET($D$1,$C$21,0)
start point will be one row above Jan, that way when Jan is chosen it will fall onto Jan.
Month number you will get from what was said earlier
and columns will depend on how you place it
YTD, you will do the same as above but have a sum
so
=sum(B3:offset ([start point],[month number],[columns]))
=SUM(D2:OFFSET($D$1,C21,0))
QTD would be easiest just plotting the sums as it would never change
So set out Q1,Q2,Q3 and Q4 as prefixed ones. Then lookup to them.
However, if you want to see the most recent quarter by a formula. On the month number list add a new column which says what quarter it is. Then
Jan 1 1
Feb 2 1
Mar 3 1
Apr 4 2
...
Dec 12 4
It should the read off a formula like so
=SUM(
OFFSET([start point],(INDEX([month number table],MATCH([month],[month list],0),3)-1)*3,0):
OFFSET([start point],INDEX(month number table],MATCH([month],[month list],0),2),0))
=SUM(
OFFSET($D$2,(INDEX($F$2:$H$13,MATCH($C$20,$F$2:$F$13,0),3)-1)*3,0):
OFFSET($D$1,INDEX($F$2:$H$13,MATCH($C$20,$F$2:$F$13,0),2),0)
)
What you are doing is to find the month at the beginning of the quarter and then sum to the current month.
Regarding this bit at the end
OFFSET([start point],(INDEX([month number table],MATCH([month],[month list],0),3)-1)*3,0):
You are finding the month quarter index number(1,2,3,4) and multiplying it by three. The reason you want to take away one before multiplying by three is because you want the start point of the quarter, thus in jan to march, this will be 0, and then you add a row to get the start point being Jan.
In Oct to Dec this will be (4-1) = 3. 3x3 = 9 which will be Oct to make Oct being the start point. Amend as need be.
The yellow section is what your actual information is presented as
The green section is your lookup area
The Blue area is information you are looking for with the lower bit reading from the lookup

Distribute value equally over weeks by start- and end-date

I want to distribute a certain value (D4:D6) equally over the week-numbers (E3:J3) by its start- and end-date (B4:C6), as shown in the example.
A formula/vba script should do the following things:
Check which week-number the start- and end-date has
Divide the value by the amount of weeks between start- and end-date
Place the values in the matching column in the same row
The example in text format to copy:
2017 2018
Start End Value 50 51 52 1 2 3
26.12.2017 04.01.2018 20 - - 10 10 - -
12.12.2017 24.12.2017 50 25 25 - - - -
11.12.2017 10.01.2018 60 12 12 12 12 12 -
Also glad about hints / ideas how single steps could be achieved.
Proof of Concept:
place the following formula in E4 and copy down and right
=IF(WEEKNUM($C4,21)-WEEKNUM($B4,21)<0,IF(OR(E$3>=WEEKNUM($B4,21),E$3<=WEEKNUM($C4,21)),$D4/IF(WEEKNUM($C4,21)-WEEKNUM($B4,21)<0,MAX(WEEKNUM(DATE(YEAR($B4),12,{28,29,30,31}),21))-WEEKNUM($B4,21)+WEEKNUM($C4,21)+1,WEEKNUM($C4,21)-WEEKNUM($B4,21)+1),0),IF(AND(E$3>=WEEKNUM($B4,21),E$3<=WEEKNUM($C4,21)),$D4/IF(WEEKNUM($C4,21)-WEEKNUM($B4,21)<0,MAX(WEEKNUM(DATE(YEAR($B4),12,{28,29,30,31}),21))-WEEKNUM($B4,21)+WEEKNUM($C4,21)+1,WEEKNUM($C4,21)-WEEKNUM($B4,21)+1),0))
Now this is a built up formula from multiple cells that I back substitute the formulas to wind up with the monstrosity above. The break down is as follows.
STEP 1
Find the start week number. Place the following in B8.
=WEEKNUM($B4,21)
STEP 2
Find the end week number. Place the following in C8.
=WEEKNUM($C4,21)
STEP 3
Determine the maximum number of weeks in a year. Thanks to Ron Rosenfeld for this formula. Place the following in D8.
=MAX(WEEKNUM(DATE(YEAR($B4),12,{28,29,30,31}),21))
STEP 4
Determine if the week is in the same year or the following year. Place the following in E8.
=C8-B8
STEP 5
Determine the number of weeks. Place the following in F8.
=IF(E8<0,D8-B8+C8+1,C8-B8+1)
STEP 6
Average the value for each week. Place the following in G8.
=D4/F8
STEP 7
Determine if the average value belongs to a date header or the value of 0 (if you want an actual dash and not just formatting 0 as a dash then change 0 to -. Place the following formula in H8.
=IF($E8<0,IF(OR(E$3>=$B8,E$3<=$C8),$G8,0),IF(AND(E$3>=$B8,E$3<=$C8),$G8,0))
Copy the H8 formula to the right and down as required.
Caveat: Will work for a 1 year spread in work weeks. I have serious doubts that it would work over multi year start and end week.
Layout of steps

Formula for row artificial shift

i've been doing this for weeks but to no avail, i'll give you the context so it'd be easier to understand: i have several sets of warehouse materiel codes sorted from smallest to largest as well as the time they need to be delivered to the workshop for processing and the amount of pallets required at each specific time frame, here is how it looks:
Mat. Code Time Pallets
65504606 07:30:00 2
65504606 10:30:00 1
65504606 13:30:00 2
65504606 16:30:00 1
65504606 19:30:00 2
65504606 22:30:00 1
65504606 01:30:00 2
65504606 04:30:00 1
I'm matching this data with another worksheet containing the information on where each individual pallet is stored, so i need to shift values in the time column so that a specific pallet is delivered on time, here's what i'd like it to look like:
Mat. Code location Time Cell shift
65504606 91-04-03/1 7 30 0
65504606 76-13-03/1 7 30 -1
65504606 97-19-03/1 10 30 -1
65504606 97-16-03/3 13 30 -1
65504606 76-19-02/1 13 30 -2
65504606 97-18-03/1 16 30 -2
65504606 97-18-03/2 19 30 -2
65504606 88-07-02/1 19 30 -3
I figured i could shift cells artificially by adding another column (cell shift - it has to be negative because the amount of rows in the sheet i'm matching with is smaller, plus i'm using INDEX - SMALL formula combination for matching each consecutive row of every set of codes), but all the formula combinations i've tried were giving me wrong numbers. The amount of pallets can vary from 0 to 9 and go in no particular order.
I know it's a lot of confusing information, but you would really help me out if you come up with a proper formula. Thanks in advance!
What you want to do is look something up in a restricted range.
What I did was restricting the range so I could use a simple VLOOKUP.
What OP asked for was an additional input to use in another formula.
=VLOOKUP(C2,OFFSET(YourFirstTableWithPalletNums!$A$1,MATCH(A2,YourFirstTableWithPalletNums!$A:$A,0)-1,1,COUNTIFS(YourFirstTableWithPalletNums!$A:$A,A2),2),2,FALSE)
P.S. Only works if the time values you look up are actually time values and not strings like the question implies.
EDIT:
=ROW(OFFSET(YourFirstTableWithPalletNums!$A$1,MATCH(WhereYouLookUpFrom!$C2,OFFSET(YourFirstTableWithPalletNums!$A$1,MATCH($A2,YourFirstTableWithPalletNums!$A:$A,0)-1,1,COUNTIFS(YourFirstTableWithPalletNums!$A:$A,$A2)),0),1))-ROW()
Then we need one more shift and then take the applicable row (we're still operating with ranges in this case). When added to the previously uploaded file it worked perfectly.

Resources