I am in the process of building a formula to split a total cost (in column J) based on start and end expenditure periods that can vary from 2021 to 2031. Based on the days between the expenditure period dates (column M), I managed to work out to split the cost using the formulas below up to 2023 but it is not consistent and at times incorrect.
In cell P5 I have the following formula. For year 2021, I seem to get the correct split result.
=IF($K5>AS5,0,$J5/$M5*(AS5-$K5))
In cell Q5, I have the following formula. For year 2022, I seem to get the correct spit as well
=MIN(IF(SUM($N5:P5)>=$J5,0,IF($L5>=AS5,$J5/$M5*(AS5-AR5),$J5/$M5*($L5-MAX(AR5,$K5)))),K5)
However, I don't get the right result in cell Q6 which has the same formula but different dates
=MIN(IF(SUM($N6:P6)>=$J6,0,IF($L6>=AS6,$J6/$M6*(AS6-AR6),$J6/$M6*($L6-MAX(AR6,$K6)))),K6)
Cell R6 shouldn't return any result because it is out of date range. This is where things get mixed up.
Note that from column AR to BC, it is all year end dates from 2020 to 2031 as shown below.
Is there a better way to tackle this sort of formula as I seem to get dragged into a long and unreliable way of doing this.
Here single function(♣) that will create a series of pro-rata multipliers (of appropriate length) for any given start/end date:
EDIT: see end of soln for extended version per OP comment to original soln...
SINGLE FUNCTION
=J11*(LET(dates,EDATE(DATE(YEAR($K11),1,1),12*(SEQUENCE(1,YEAR($L11)-YEAR($K11)+2,1))),IF(dates<K11,K11,IF(dates<L11,dates,L11)))-LET(dates,EDATE(DATE(YEAR($K11)-1,1,1),12*(SEQUENCE(1,YEAR($L11)-YEAR($K11)+2,1))),IF(dates<K11,K11,IF(dates<L11,dates,L11))))/(L11-K11)
It may appear somewhat unwieldy in length, but it is far more robust (and concise) compared to the combination of steps/series you have created. What's more, it returns the precise answer RE: pro-rata payments and is guarenteed to never over/under-run RE: total payment (by design).
BREAK-DOWN
Comprises 3 distinct parts (some of which are similar in pattern/formation):
1] First part - create a series (array) of years spanning start-end dates:
=LET(dates,EDATE(DATE(YEAR($K5)-1,1,1),12*(SEQUENCE(1,YEAR($L5)-YEAR($K5)+2,1))),IF(dates<K5,K5,IF(dates<L5,dates,L5)))
Thanks to the lovely Spill functionality the new Office 365 variant Excel boasts, you never have to worry about how many years are required -- so long as you have the space to the right of this workbook (would be unusual otherwise - assuming you start in column O and clear any content to the right of this, you'd need an end date beyond the year 2557 (26th century) to run out of columns! ☺
2] Second part is merely a replica of the firs series, albeit shifted to the right 'once' (so starts with the 2nd element in the 1st series):
=LET(dates,EDATE(DATE(YEAR($K5),1,1),12*(SEQUENCE(1,YEAR($L5)-YEAR($K5)+2,1))),IF(dates<K5,K5,IF(dates<L5,dates,L5)))
3] Third part - you have the basic ingredients from parts 1 and 2 to complete the required task easily: simply deduct series 2 from 1 (giving days between successive dates in series 1 - i.e. days for each year between start and end dates), divide by total days (to yield pro-rata multipliers), and then multiply these by the total £amount and voila - you have your series!
=J5*(O6#-O5#)/(M5)
♣ Caveat(s) - assuming you have Office 365 compatible version of Excel (which is quite common nowadays)
*EDIT - EXTENDED VERSION
Given above, the following extends this to align monetary results (1st table, o11:w21) within respective calendar period columns (spanning the entire period in question).
This soln:
Determines header row based upon the number of columns & corresponding calender periods (financial yrs commencing 1/1) as an array function (i.e. dynamic range)
Utilises a modified version of the eq. provided for dates arrage (refer: "First Part", original soln)
Comment - same caveats as before - i.e. Office 365 etc.
Screenshot(s)/here refers:
DATES (HEADER) - Y10 (array)
=LET(y_,MIN(K11:K21),x_,MAX(L11:L21),EDATE(DATE(YEAR(y_)-1,1,1),12*(SEQUENCE(1,YEAR(x_)-YEAR(y_)+2,1))))
Comment - enter once within single cell Y10 - i.e. as an array function with Spill to right
ALIGNED/SHIFTED FINANCIALS - Y11:Y21 (each cell in col is an array)
=IFERROR(IF(Y$10#<EDATE(K11,-12),"",IF(Y$10#>EDATE(L11,12),"",INDEX(O11#,1,MATCH(Y$10#,EDATE(DATE(YEAR($K11)-1,1,1),12*(SEQUENCE(1,YEAR($L11)-YEAR($K11)+2,1))),0)))),"")
Comment - enter this as an array fn. (#SPILL! to the right) in each cell within column Y (can drag this function down Y11:Y21 as required)
I'm having a hard time getting my head around what I think is a simple enough problem.
I have an Excel table of hours by day for each user i.e.:
Date1, Date1+1, Date1+2, Date1+3,... Date1+n
User1 8 8 4 6 ... 2
User2 5 2 8 3 ... 7
User3 0 7 5 0 ... 8
For forecasting purposes this grid looks several months into the future.
I do my work daily, others want it by week. I'd like to automatically generate the same table of data but rolled up by WeekNum.
I tried setting a year-weeknum at the top of the daily table and then using a SumIfs function to compare the user name and week num to sum up the daily hours in another tab for weekly data but I just couldn't get it to function properly.
=SUMIFS('Act - Forecast Hours'!$G$6:$AAL$35,'Act - Forecast Hours'!$A26,$A25,'Act - Forecast Hours'!S$4,O$3)
I think I'm overcomplicating a solution, any help is appreciated.
TIA
Rob
OK, I may have come up with an approach.
Since on my main Hourly Sheet the format is fixed, i.e. each week is 7 days and increments.
I setup a second sheet where I called a vertical and a horizontal offset and used the following formula:
=SUM(OFFSET('Act - Forecast Hours'!$G$9,$A5,D$2,1,7))
$A5 and D$2 refer to offset counts that increment by 7. As you copy the formula to each cell it increments the Row / Column to point to the right spot. Then for the Height and Width I look at a grid 1 row high and 7 wide to select each day of the week.
It works, I'm happy. I'm certainly interested in a more refined approach if there is one :-)
Thank You to anyone that does read through the question!
Regards
Rob
Data below shows the maximum score for every question in an exam, and the score of a student. What excel formula can I use to calculate student score using his best 7 questions answered?
Question 1 2 3 4 5 6 7 8 9 Total
Marks 10 15 10 5 15 10 10 15 10 100
Student score
John D 0 6.5 4 0 3 0 7 2 5 27.5
I think I've come up with something that should almost fulfill your requirement.
Solution can be broken down into following steps:
1. Get the top 7 scoring answers (this is based on your comment where you mentioned that 6 out 10 is better than 6.5 out of 15). As per the data provided in the question best performing score would be 7/10 followed by 5/10, 6.5/15, and so on.
Write the below formula in the Cell B6 and drag/copy across till H6 to get these values.
=LARGE(($B$4:$J$4)/($B$2:$J$2),COLUMN(B1)-COLUMN($B$1:$H$1)+1)
This is an array formula so commit it by pressing Ctrl+Shift+Enter
2. Now we have top 7 scores in Row 6. On the basis of these values get their corresponding marks. For this enter the following formula in Cell B7
=INDEX($B$2:$J$2,1,SMALL(IF((($B$4:$J$4)/($B$2:$J$2)=B6),COLUMN($B$1:$J$1)-COLUMN($B$1)+1),COUNTIF($B$6:B6,B6)))
and drag/copy across till H7.
Again this is an array formula.
3. After getting marks its time to get scores. Use below formula in Cell B8 and drag/copy across till H8
=INDEX($B$4:$J$4,1,SMALL(IF((($B$4:$J$4)/($B$2:$J$2)=B6),COLUMN($B$1:$J$1)-COLUMN($B$1)+1),COUNTIF($B$6:B6,B6)))
This is an array formula too.
4. In Cell K7 and Cell K8 enter =SUM(B7:H7) and =SUM(B8:H8) respectively.
5. To get the percentage of the top 7 scoring questions with respect to marks allotted write =K8/K7.
Drawback of this solution:
When ever there is tie in values in the Row 6 this may not give you desired result. By saying tie I do not mean same score (eg. 2/10, 2/15) instead I am talking about performance on each question like 2/10 and 3/15 both will give same result as far as performance is concerned.
In the sample data provided in the question John has three scores of 0's (one out of 10 and other two out of 15). Mathematically all three are same however if you want to include score of 0/10 in top 7 considering that it is better than 0/15, this may not happen. In case of tie the above formulas will get value in the order of occurrence i.e. if 0/15 appears before 0/10 then its 0/15 that will be considered in the formula and not 0/10. See the image for reference.
If you have any queries let me know.
Currently I am using the following formula:
=1 + (FLOOR((ROW()-2);5) / 5) + (FLOOR((ROW()-2);5) / 5) * 6
to change the numbers by 7 in different intervals and everything is working fine and you can see column A. But numbers should change by 15 for every 5th change and again the rest 4 changes should change by 7 (see in column B):
.
Is it possible to build a formula like that?
I changed your formula a bit to be shorter and a little safer:
=1+(INT((ROWS($C$1:C2)-2)/5)*7)+INT((ROWS($C$1:C2)-2)/20)*8
The first part alone would be =1+(INT((ROWS($C$1:C2)-2)/5)*7) and the added part takes care of the changes at the 5th change.
Hopefully, that will suit your needs better!
Addendum:
Couple of notes regarding the formula:
INT((ROWS($C$1:C2)-2)/5)*7
^ ^
a b
a gives the frequency when 'change' of b has to be applied. So in the above, 7 will be added after 5 rows, and extending the logic to the other part of the final formula, 8 is being added on top of the first 7 (total 15) added every 20 rows (i.e. after 4 changes each of 5 rows).
I believe what you are looking for boils down to adding another 8 every 20th row. This can be achieved by adding FLOOR((ROW()-2)/20;1)*8 to your formula.
I have a question about excel.
There is a sports tournament with multiple phases. And the results page looks something like this:
rank phase1 phase2
1 TOM ALBERT
2 MATT TOM
3 ROBIN MATT
The first place gets 5 points, second 3 and third 1 points.
So the summary I would like to get is like this
rank name phase1 phase2 total
1 TOM 5 3 8
2 ALBERT 0 5 5
3 MATT 3 1 4
4 ROBIN 1 0 1
I cant figure out how to generate it simply, so if I copy-paste the results from phase3 to somewhere in my excel sheet, the summary page would also update.
If you can support me with advice or just a working template, I would be thankful!
Thank you for your time!
I've done you a basic example below...just list all 50 players in the summary page and copy the formula down as it is - as per the question it only records a value for the top 3 places, hope this helps if not please let me know :)
Example file here
Assuming the structure you defined and that when you paste phase 3 it will have its header ("phase3") on the same row as the other results, you could have the following formula on your Table 2:
{=SUM(IF(IFERROR(MATCH($B2,INDIRECT("Sheet1!"&CHAR(64+MATCH(C$1,Sheet1!$1:$1,0))&":"&CHAR(64+MATCH(C$1,Sheet1!$1:$1,0))),0)-1,0)={1,2,3},{5,3,1},0))}
Note: entered as Array formula: CTRL + SHIFT + ENTER
Formula uses the Table 2 headers ("phase1","phase2", etc.) and the players names to find the results for each phase. It then uses the predefined arrays that determine points given per position. The final sum is to bring the result that are in array (other values in array are 0) into single value.
Total would sum results per player.
Under the rank cells you would place the following formula:
=RANK(F2,$F:$F)
Which would provide you the rank of each player (Column F containing the totals).
Note that this would not sort your rank automatically but you could easily do this with Sorting or Autofilter. Hope this helps. Cheers.