Converting algorithm to formula ( embedded IF AND )

Captain Hindsight

New Member
Joined
Oct 9, 2013
Messages
46
Morning,

I have the following algorithm:
N</SPAN>Y</SPAN>Y</SPAN>N</SPAN>Y</SPAN>Y</SPAN>Y</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL><COL><COL><COL><COL><COL></COLGROUP>

The part I have bolded repeats infinitely afterwards. I need to convert this into an excel formula.

Where a 'Y' occurs, I want excel to return me the value in cell C2.

I have the following formula:

=IF(AND($D$7<>0,OR(D$3=$B5,C$3=$B5,D5+C5+B5=(2*$C$2))),$C$2,0)

which gives me the NYYY, NYYY, NYYY etc.

I have done this by saying if the previous month's column cell = the current month's row cell, return a value to get the first 'NY' part. I then repeated this to get to 'NYY', then have the condition that if the sum of the previous 3 cells = 2*the value in C2, give me a value to get NYYY, NYYY, NYYY etc.

I need to add in something to get that first part of the algorithm above (not in bold).

Any suggestions?

Thank you
</SPAN></SPAN></SPAN></SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL><COL><COL><COL><COL><COL></COLGROUP>
 
"I also need to be able to drag it down."

If by that you mean that, when you drag it down, the same repeating pattern as in the row above is reproduced, then yes, you can.

"If we are in row 6, that $D6>0"

Ok. Think I get that.

"If we are in F5, that E5 = B5. This condition identifies when to start applying the pattern. It is set to look at the previous month ref in the column as the first month is 0 (as per the pattern)."

But not sure about this one. Do you mean that every previous value in a row will be compared to the corresponding entry in column B? But won't that only happen if that entry is either 0 or equal to the value in C2?

Without that last condition, in E3:

=IF($D3>0,IF(COLUMNS($A:A)<4,IF(MOD(COLUMNS($A:A),3)=1,0,$C$2),IF(MOD(COLUMNS($A:A),4)=0,0,$C$2)),"")

Regards
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
"I also need to be able to drag it down."

If by that you mean that, when you drag it down, the same repeating pattern as in the row above is reproduced, then yes, you can.

"If we are in row 6, that $D6>0"

Ok. Think I get that. I mean that if the value in column D is 0 (no deliveries), I don't want the pattern to be applied I want 0's all the way long.

"If we are in F5, that E5 = B5. This condition identifies when to start applying the pattern. It is set to look at the previous month ref in the column as the first month is 0 (as per the pattern)."

But not sure about this one. Do you mean that every previous value in a row will be compared to the corresponding entry in column B? But won't that only happen if that entry is either 0 or equal to the value in C2? I mean that, if you imagine a grid with months going along the top (Jan - Dec) and going vertically (Jan - Dec) with the pattern being applied going down to fill in the grid, that I want the pattern to start being applied where the previous months column ref (e.g. Feb), is equal to the current months row ref (would be March). The reason for this is that I don't want to see any values, until the month of the delivery i.e. if the pattern begins in June, I want to see nothing before July (because the first part of the pattern is an N, there would be nothing in June).

Without that last condition, in E3:

=IF($D3>0,IF(COLUMNS($A:A)<4,IF(MOD(COLUMNS($A:A),3)=1,0,$C$2),IF(MOD(COLUMNS($A:A),4)=0,0,$C$2)),"")

Regards


please see the comments I have inserted into your answer.

Thanks again for your help so far
 
Upvote 0
So can you confirm your previous example: "If we are in F5, that E5 = B5.</SPAN>"?

This seems to contradict what you have just said about the column and row headers as, unless I'm mistaken, E5 is not </SPAN>a column header - you said these were in row 3 (?)

Regards</SPAN>
 
Upvote 0
"If we are in F5, that E3 = B5"

Ok, but is this still correct? Are you sure you don't want the pattern to start, and be repeated, for all months which are after a certain date? Currently, as with the above criteria applied to every single cell, this is what you'd have (in E5):

=IF($B5=D$3,IF($D5>0,IF(COLUMNS($A:A)<4,IF(MOD(COLUMNS($A:A),3)=1,0,$C$2),IF(MOD(COLUMNS($A:A),4)=0,0,$C$2)),0),"")

Are you sure it shouldn't be something like:

=IF($B5>=D$3,IF($D5>0,IF(COLUMNS($A:A)<4,IF(MOD(COLUMNS($A:A),3)=1,0,$C$2),IF(MOD(COLUMNS($A:A),4)=0,0,$C$2)),0),"")

or perhaps (not sure which way round these row/column rules should be):

=IF($B5<=D$3,IF($D5>0,IF(COLUMNS($A:A)<4,IF(MOD(COLUMNS($A:A),3)=1,0,$C$2),IF(MOD(COLUMNS($A:A),4)=0,0,$C$2)),0),"")

If that doesn't help, I'm afraid I think I'm going to have to call it a day!

Regards
 
Upvote 0
"If we are in F5, that E3 = B5"

Ok, but is this still correct? Are you sure you don't want the pattern to start, and be repeated, for all months which are after a certain date? Currently, as with the above criteria applied to every single cell, this is what you'd have (in E5):

=IF($B5=D$3,IF($D5>0,IF(COLUMNS($A:A)<4,IF(MOD(COLUMNS($A:A),3)=1,0,$C$2),IF(MOD(COLUMNS($A:A),4)=0,0,$C$2)),0),"")

Are you sure it shouldn't be something like:

=IF($B5>=D$3,IF($D5>0,IF(COLUMNS($A:A)<4,IF(MOD(COLUMNS($A:A),3)=1,0,$C$2),IF(MOD(COLUMNS($A:A),4)=0,0,$C$2)),0),"")

or perhaps (not sure which way round these row/column rules should be):

=IF($B5<=D$3,IF($D5>0,IF(COLUMNS($A:A)<4,IF(MOD(COLUMNS($A:A),3)=1,0,$C$2),IF(MOD(COLUMNS($A:A),4)=0,0,$C$2)),0),"")

If that doesn't help, I'm afraid I think I'm going to have to call it a day!

Regards

That last formula is very close!

I am now getting values returned in the correct cell, and on the first row it is in the correct pattern.

However as the pattern is NYY, NYYY, NYYY
in row 2 (Feb 16) I am now getting YY, NYYY, NYYY
then in row 3 I am geyying Y, NYYY, NYYY
row 4 I am getting NYYY, NYYY

etc.

This pattern needs to begin to be applied, from where $B5 = D$3

So close now!!

so that in Feb 16 column, Jan 15 (row), we are getting the first part of the pattern (the 0).

For visual:

______JFM AMJJ ASON < months

Jan 16: NYY NYYY NYYY
Feb 16: 0NY YNYY YNYY
Mar 16 00N YYNY YYNY

As you can see the pattern begins to be applied from the month of introduction.
 
Last edited:
Upvote 0
Sorry - completely lost now. Unless you can provide a link to a sheet with your desired results I'll have to wish you the best of luck with it.

Regards
 
Upvote 0
Sorry - completely lost now. Unless you can provide a link to a sheet with your desired results I'll have to wish you the best of luck with it.

Regards


I want it to look like:


Batch 1</SPAN>0</SPAN>1</SPAN>2</SPAN>3</SPAN>4</SPAN>5</SPAN>
1</SPAN>239.555</SPAN>1</SPAN>2</SPAN>3</SPAN>4</SPAN>5</SPAN>6</SPAN>7</SPAN>8</SPAN>9</SPAN>10</SPAN>11</SPAN>
Dec-15</SPAN>Jan-16</SPAN>Feb-16</SPAN>Mar-16</SPAN>Apr-16</SPAN>May-16</SPAN>Jun-16</SPAN>Jul-16</SPAN>Aug-16</SPAN>Sep-16</SPAN>Oct-16</SPAN>
Month of introduction</SPAN>Date</SPAN>Delivered</SPAN>>0 ?</SPAN>
1</SPAN>Dec-15</SPAN>1</SPAN>1</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>
2</SPAN>Jan-16</SPAN>3</SPAN>1</SPAN>0</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>
3</SPAN>Feb-16</SPAN>2</SPAN>1</SPAN>0</SPAN>0</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>
4</SPAN>Mar-16</SPAN>2</SPAN>1</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>
5</SPAN>Apr-16</SPAN>4</SPAN>1</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>
6</SPAN>May-16</SPAN>3</SPAN>1</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>
7</SPAN>Jun-16</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>
8</SPAN>Jul-16</SPAN>3</SPAN>1</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>
9</SPAN>Aug-16</SPAN>2</SPAN>1</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>
10</SPAN>Sep-16</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>
11</SPAN>Oct-16</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL><COL span=2><COL span=11></COLGROUP>


Currently looks like:
Batch 1</SPAN>0</SPAN>1</SPAN>2</SPAN>3</SPAN>4</SPAN>5</SPAN>
1</SPAN>239.555</SPAN>1</SPAN>2</SPAN>3</SPAN>4</SPAN>5</SPAN>6</SPAN>7</SPAN>8</SPAN>9</SPAN>10</SPAN>11</SPAN>
Dec-15</SPAN>Jan-16</SPAN>Feb-16</SPAN>Mar-16</SPAN>Apr-16</SPAN>May-16</SPAN>Jun-16</SPAN>Jul-16</SPAN>Aug-16</SPAN>Sep-16</SPAN>Oct-16</SPAN>
Month of introduction</SPAN>Date</SPAN>Delivered</SPAN>>0 ?</SPAN>
1</SPAN>Dec-15</SPAN>1</SPAN>1</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>
2</SPAN>Jan-16</SPAN>3</SPAN>1</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>
3</SPAN>Feb-16</SPAN>2</SPAN>1</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>
4</SPAN>Mar-16</SPAN>2</SPAN>1</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>
5</SPAN>Apr-16</SPAN>4</SPAN>1</SPAN>239.555</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>
6</SPAN>May-16</SPAN>3</SPAN>1</SPAN>239.555</SPAN>0</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>
7</SPAN>Jun-16</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>
8</SPAN>Jul-16</SPAN>3</SPAN>1</SPAN>239.555</SPAN>239.555</SPAN>239.555</SPAN>
9</SPAN>Aug-16</SPAN>2</SPAN>1</SPAN>239.555</SPAN>239.555</SPAN>
10</SPAN>Sep-16</SPAN>0</SPAN>0</SPAN>0</SPAN>
11</SPAN>Oct-16</SPAN>0</SPAN>0</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL><COL span=2><COL span=11></COLGROUP>
 
Upvote 0
Hi,

Try this:

=IF($D5>0,IF(COLUMNS($A:A)<ROWS($1:1),0,IF(COLUMNS($A:A)<3+ROWS($1:1),IF(COLUMNS($A:A)+ROWS($1:1)=2*ROWS($1:1),0,$C$2),IF(MOD(1+COLUMNS($A:A)-ROWS($1:1),4)=0,0,$C$2))),0)

Regards
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,463
Messages
6,124,963
Members
449,200
Latest member
indiansth

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