Formula when between weeks, on rolling calendar

wiseone

Board Regular
Joined
Mar 14, 2015
Messages
144
Hi All,

I stumped myself with this one.

I have a sheet with columns numbered 1 through 52 (representing weeks of the year). The column headers can change based on another selection to keep it a fiscal year (start with 1, end with 52), OR they can be updated to show the current week in the first column and roll over after week 52. There is always a total of 52 columns as shown in is example:

Column Headers Example 1:
123..........505152

<tbody>
</tbody>


Column Headers Example 2

49505152123...4748

<tbody>
</tbody>


I also have 2 columns ahead of these weeks indicating a start week and an end week, which will be used to populate data between and including those 2 weeks. A formula is under each of the week column headers (there are multiple rows, but for simplicity I displayed 1 row of data.)

Start WeekEnd Week1234.........505152
410Formula hereFormula hereFormula hereFormula hereFormula hereFormula hereFormula hereFormula hereFormula hereFormula here

<tbody>
</tbody>

Can you help make a formula which determines when to populate data between the start and end week, taking into account that weeks can roll over (or wrap around a year). There are several scenarios I can think of which makes 1 formula a challenge.

Scenario 1 - Week columns start at 1 and data is between a lower and higher week, and weeks requiring data do not roll over the year.
Start WeekEnd Week1234.........505152
24Data should populate heredata should populate heredata should populate here

<tbody>
</tbody>



Scenario 2 - Week columns start at 1, but data rolls over the year, with start week lower than end week.
Start WeekEnd Week123456...505152
62Data should populate hereData should populate hereData should populate hereData should populate hereData should populate hereData should populate hereData should populate here

<tbody>
</tbody>

Scenario 3 - Columns do not start at 1, and data rolls over the year, with start week lower than end week.
Start WeekEnd Week10111213......6789
610Data should populate hereData should populate hereData should populate hereData should populate hereData should populate here

<tbody>
</tbody>

Scenario 4 - Columns do not start at one, and start week higher than end week.
Start WeekEnd Week49505152123...4748
502Data should populate hereData should populate hereData should populate hereData should populate hereData should populate here

<tbody>
</tbody>

Here is an example of what I did, but it fails when the weeks requiring data wrap around the year because its basing it on column location.

Weeks of the year are in in AM6:CL6.
Start week is in AK7
End Week is in AL7

=IF(OR(MATCH(AM$6,$AM$6:$CL$6,0<match($ak7,$am$6:$cl$6,0),match(am$6,$am$6:$cl$6,0)>MATCH($AL7,$AM$6:$CL$6,0)),"","Calculation formula here")

thanks in advance!

Robin</match($ak7,$am$6:$cl$6,0),match(am$6,$am$6:$cl$6,0)>
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi!

Try the formula below in C2 and copy to the right:

=IF($B2>$A2,IF(MEDIAN($A2,$B2,C1)=C1,"For",""),IF((COUNTIF($A2:$B2,C1)=0)*MEDIAN($A2,$B2,C1)=C1,"","For"))

Markmzz
 
Upvote 0
Hi!

A small modification in my last formula:

=IF(MEDIAN($A2,$B2,C1)=C1,IF($B2>$A2,"For",IF(COUNTIF($A2:$B2,C1),"For","")),IF($B2>$A2,"","For"))

Do some tests.

Markmzz
 
Upvote 0
Hi!

Another version:

=IF((MEDIAN($A2,$B2,C1)=C1)+($B2>$A2)+COUNTIF($A2:$B2,C1)=1,"","For")


ABCDEFGHIJAWAXAYAZBABBBC
1Start WeekEnd Week12345678474849505152
224ForForFor
3Scenario 1
4
5Start WeekEnd Week12345678474849505152
662ForForForForForForForForForForFor
7Scenario 2
8
9Start WeekEnd Week1011121314151617456789
10610ForForForForFor
11Scenario 3
12
13Start WeekEnd Week495051521234434445464748
14502ForForForForFor
15Scenario 4
16
*********************************************************************

<tbody>
</tbody>

Markmzz
 
Upvote 0
Ok this works! Thanks again! I could use your help with one part of my formula that isn't working. There is a static row above this table in row 1:1 which contains only blanks 1s or 2s. I need to SUMIF row 1:1 if the row with your formula says to execute the formula. (Or simply said: SUM row 1:1 if the formula in row 3:3 should return a result)

Here is my formula with your solution incorporated and the problem section is underlined:

<match($aj7,$am$6:$cl$6,0),(median($ak7,$al7,am$6)=am$6)+($al7><match($aj7,$am$6:$cl$6,0),"",$ai7 (5*52-sum($am$1:$cl$1))*(5-am$1))))
<match($aj8,$am$6:$cl$6,0),"",$ai8 (5*52-sum($am$1:$cl$1))*(5-am$1))))
=IF(OR($AI7="",$AJ7="",$G7="Not Active",$G7=""),"",IF(AND($AK7<>"",$AL7<>""),IF(OR(MATCH(AM$6,$AM$6:$CL$6,0)<MATCH($AJ7,$AM$6:$CL$6,0),(MEDIAN($AK7,$AL7,AM$6)=AM$6)+($AL7>$AK7)+COUNTIF($AK7:$AL7,AM$6)=1),"",$AI7/(5*IF($AL7>$AK7,$AL7-$AK7+1,53-$AK7+$AL7)-SUM(INDIRECT(ADDRESS(1,MATCH($AK7,$6:$6,0))&":"&ADDRESS(1,MATCH($AL7,$6:$6,0)))))*(5-AM$1)),IF(MATCH(AM$6,$AM$6:$CL$6,0)<MATCH($AJ7,$AM$6:$CL$6,0),"",$AI7/(5*52-SUM($AM$1:$CL$1))*(5-AM$1))))


The problem with the current formula is the INDIRECT(MATCH()) is returning a wrong range for all scenarios. I feel like I have to use your criteria to SUMIFS, but don't know how to build a SUMIFS with ALL these criteria.

IF(OR(MATCH(AM$6,$AM$6:$CL$6,0)<MATCH($AJ7,$AM$6:$CL$6,0),(MEDIAN($AK7,$AL7,AM$6)=AM$6)+($AL7>$AK7)+COUNTIF($AK7:$AL7,AM$6)=1)</match($aj8,$am$6:$cl$6,0),"",$ai8></match($aj7,$am$6:$cl$6,0),"",$ai7></match($aj7,$am$6:$cl$6,0),(median($ak7,$al7,am$6)=am$6)+($al7>
 
Last edited:
Upvote 0
Ok trying again:

Here is my formula with problem section underlined.

=IF(OR($AI7="",$AJ7="",$G7="Not Active",$G7=""),"",IF(AND($AK7< >"",$AL7< >""),IF(OR(MATCH(AM$6,$AM$6:$CL$6,0)< MATCH($AJ7,$AM$6:$CL$6,0),(MEDIAN($AK7,$AL7,AM$6)=AM$6)+($AL7>$AK7)+COUNTIF($AK7:$AL7,AM$6)=1),"",$AI7/(5*IF($AL7>$AK7,$AL7-$AK7+1,53-$AK7+$AL7)-SUM(INDIRECT(ADDRESS(1,MATCH($AK7,$6:$6,0))&":"&ADDRESS(1,MATCH($AL7,$6:$6,0)))))*(5-AM$1)),IF(MATCH(AM$6,$AM$6:$CL$6,0)< MATCH($AJ7,$AM$6:$CL$6,0),"",$AI7/(5*52-SUM($AM$1:$CL$1))*(5-AM$1))))

Here are the conditions that i feel like need to be used to SUM IF

IF(OR(MATCH(AM$6,$AM$6:$CL$6,0)< MATCH($AJ7,$AM$6:$CL$6,0),(MEDIAN($AK7,$AL7,AM$6)=AM$6)+($AL7>$AK7)+COUNTIF($AK7:$AL7,AM$6)=1)
 
Upvote 0
Ok trying again:

Here is my formula with problem section underlined.

=IF(OR($AI7="",$AJ7="",$G7="Not Active",$G7=""),"",IF(AND($AK7< >"",$AL7< >""),IF(OR(MATCH(AM$6,$AM$6:$CL$6,0)< MATCH($AJ7,$AM$6:$CL$6,0),(MEDIAN($AK7,$AL7,AM$6)=AM$6)+($AL7>$AK7)+COUNTIF($AK7:$AL7,AM$6)=1),"",$AI7/(5*IF($AL7>$AK7,$AL7-$AK7+1,53-$AK7+$AL7)-SUM(INDIRECT(ADDRESS(1,MATCH($AK7,$6:$6,0))&":"&ADDRESS(1,MATCH($AL7,$6:$6,0)))))*(5-AM$1)),IF(MATCH(AM$6,$AM$6:$CL$6,0)< MATCH($AJ7,$AM$6:$CL$6,0),"",$AI7/(5*52-SUM($AM$1:$CL$1))*(5-AM$1))))

Here are the conditions that i feel like need to be used to SUM IF

IF(OR(MATCH(AM$6,$AM$6:$CL$6,0)< MATCH($AJ7,$AM$6:$CL$6,0),(MEDIAN($AK7,$AL7,AM$6)=AM$6)+($AL7>$AK7)+COUNTIF($AK7:$AL7,AM$6)=1)

Hi!

Try this two new formulas:

=IF($AL7>$AK7,IF(AM6>=$AK7,IF(AM6<=$AL7,"For",""),""),IF((AM6>=$AK7)+(AM6<=$AL7),"For",""))

=SUMPRODUCT(($AL7>$AK7)*(AM6:CL6>=$AK7)*(AM6:CL6<=$AL7)+($AL7<=$AK7)*((AM6:CL6>=$AK7)+(AM6:CL6<=$AL7)),$AM$1:$CL$1)


Markmzz
 
Upvote 0
Hi!

Try this two new formulas:

=IF($AL7>$AK7,IF(AM6>=$AK7,IF(AM6<=$AL7,"For",""),""),IF((AM6>=$AK7)+(AM6<=$AL7),"For",""))

=SUMPRODUCT(($AL7>$AK7)*(AM6:CL6>=$AK7)*(AM6:CL6<=$AL7)+($AL7<=$AK7)*((AM6:CL6>=$AK7)+(AM6:CL6<=$AL7)),$AM$1:$CL$1)


Markmzz

Another formula:

=IF(($AL7>$AK7)*(AM6>=$AK7)*(AM6<=$AL7)+($AL7<=$AK7)*((AM6>=$AK7)+(AM6<=$AL7)),"For","")

Markmzz
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top