Understanding this formula:=IF(TC[[#This Row],[Page]]="/","Home",IF(TC[[#This Row],[Page]]="/blog/","Blog Home",IF(ISNUMBER(SEARCH("/blog/category/",T

Pingbat

New Member
Joined
Jun 20, 2016
Messages
20
Hi from sunny 16 degrees C york UK,

I would to make sure i understand this formula applied to the table below:

=IF(TC[[#This Row],[Page]]="/","Home",IF(TC[[#This Row],[Page]]="/blog/","Blog Home",IF(ISNUMBER(SEARCH("/blog/category/",TC[[#This Row],[Page]])),"Blog Category",IF(ISNUMBER(SEARCH("/blog/",TC[[#This Row],[Page]])),"Blog Post","Other"))))

blog-post-cat-if.png


Ok so here are my question:

1: Why is function "IF(ISNUMBER" introduced later in the formula when earlier in the formula it's not needed

Thanks in advance,
David
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
The first two check for the exact value of the whole cell. The ones with the ISNUMBER allow the cell to have other things in it as well but the part it's looking for must be found in there somewhere.
 
Upvote 0
The SEARCH function returns the numerical position of the start of the required text string, if it is contained within the text ofTC[[#ThisRow],[Page]]. In the screenshot shown, if the text is present it is at the start of the text, so returns the number 1, but it would still find the text if other characters preceded it, just returning a larger number. If the text is not found, SEARCH returns the #VALUE error. So if it is present, a number is returned and that's what you are looking for.
 
Upvote 0
Re: Understanding this formula:=IF(TC[[#This Row],[Page]]="/","Home",IF(TC[[#This Row],[Page]]="/blog/","Blog Home",IF(ISNUMBER(SEARCH("/blog/category/",TC[[#This Row],[Page]])),"Blog Category&am

The first two check for the exact value of the whole cell. The ones with the ISNUMBER allow the cell to have other things in it as well but the part it's looking for must be found in there somewhere.

Perfect thank you :-)
 
Upvote 0
Re: Understanding this formula:=IF(TC[[#This Row],[Page]]="/","Home",IF(TC[[#This Row],[Page]]="/blog/","Blog Home",IF(ISNUMBER(SEARCH("/blog/category/",TC[[#This Row],[Page]])),"Blog Category&am

Grazie mille :-)
 
Upvote 0
Got another question for anyone who's got the patience...

With the risk of getting really confused I can tell this is a nested formula with lots of opening and closing brackets. Maybe i need to take a step back and understand nested formulas but here goes...

"Why does it end with 4 closing brackets e.g ))))"? & Generally how can a beginner get ti understand opening a clossing brackets in excel formulas"?

Thanks,
David
 
Upvote 0
Re: Understanding this formula:=IF(TC[[#This Row],[Page]]="/","Home",IF(TC[[#This Row],[Page]]="/blog/","Blog Home",IF(ISNUMBER(SEARCH("/blog/category/",TC[[#This Row],[Page]])),"Blog Category&am

The normal syntax of an IF function is

IF (logical_test, [value_if_true], [value_if_false])

In your formula there's four nested IF functions: IF (logical_test1, value_if_true, IF(logical_test2, value_if_true..

Since there's four of them they all need to be closed at the end, you need the four closing brackets.

I guess the only way to understand the brackets is to build the complex formulas from tiny simple bits and start stacking them into a single cell so that you'll always know what they're doing and where in the formula you're going. In theory, you should always end up with the right amount of closing brackets if you added them right after you add the opening bracket, but I don't think anybody does it that way.
 
Upvote 0
Re: Understanding this formula:=IF(TC[[#This Row],[Page]]="/","Home",IF(TC[[#This Row],[Page]]="/blog/","Blog Home",IF(ISNUMBER(SEARCH("/blog/category/",TC[[#This Row],[Page]])),"Blog Category&am

Hi @Pingbat, sounds like you need some really good basic training in Excel formulas. I can recommend YouTube Excelisfun.

But in broad terms, this is what you need to know. All functions in Excel have the same syntax - so once you have learned one, you can use them all. In generic terms, any function can be written like this:
=FUNCTION(argument1, argument2, … argn)
where:
The first character must be = as this is a formula. This is not strictly part of the function, and does not appear before internal (nested) functions)
FUNCTION is the name of the function, whatever it might be. There are about 500 of them - take your pick!
Arguments are the pieces of information that your chosen function needs in order to do its job. 500 different functions, 500 different jobs. You can have from 0 to 255 arguments.

0 arguments e.g. TODAY(), NOW(), PI()
1 argument e.g. AVERAGE) - B3:B8 is a RANGE of cells, expressed by giving top left : bottom right.
2 arguments e.g. ROUND(B9,2)
3 arguments e.g. IF(condition to test, result if test is TRUE, result if FALSE)
etc.

Which brings me to your formula:
=IF(TC[[#This Row],[Page]]="/","Home",IF(TC[[#This Row],[Page]]="/blog/","Blog Home",IF(ISNUMBER(SEARCH("/blog/category/",TC[[#This Row],[Page]])),"Blog Category",IF(ISNUMBER(SEARCH("/blog/",TC[[#This Row],[Page]])),"Blog Post","Other"))))

First, let me replace
TC[[#This Row],[Page]]

with TCP (!) for ease of typing - and reading (don't do this in Excel, though, it will break your formula!). (BTW if you upgrade from Excel 2007, you'll find that they tidied up Table references in later versions and they become a lot more readable!). So your formula is now:

=IF(TCP="/","Home",IF(TCP="/blog/","Blog Home",IF(ISNUMBER(SEARCH("/blog/category/",TCP)),"Blog Category",IF(ISNUMBER(SEARCH("/blog/",TCP)),"Blog Post","Other"))))

So what we have is:

=IF(TCP="/", "Home", ...
If TCP is "/" put the entry "Home" Otherwise...

IF(TCP="/blog/","Blog Home", ...
… if TCP is "/blog/", put "Blog Home", Otherwise...

IF(ISNUMBER(SEARCH("/blog/category/",TCP)),"Blog Category", ...
... if what you get when you look for the partial string "/blog/category/" is a number (the start position), put "Blog Category", Otherwise ...

IF(ISNUMBER(SEARCH("/blog/",TCP)),"Blog Post", ...
... if your search finds "/blog/", put "Blog Post" - (note that you have already eliminated Blog Category), Otherwise ...

"Other"
Put "Other"

)
Close the bracket for the 4th (inside) IF function as it is now complete. This was the final argument in the 3rd IF function so ...

)
Close the bracket for the 3rd IF function as it is now complete. This was the final argument in the 2nd IF function so ...
)
Close the bracket for the 2nd IF function as it is now complete. This was the final argument in the 1st IF function so ...

)
Close the bracket for the 1st IF function as it is now complete.

Phew! I hope you followed that! The brackets can be confusing, but Microsoft tries to help by colour-coding them. Remember that each function is following the rule: function name, open bracket, arguments, close bracket. Also, if you click inside a formula, you will see a yellowish tooltip box, describing the function you are in. Everything in this is a hyperlink: the function name will take you to Help on that function, while the arguments will highlight exactly the part that is that argument.

Good luck and Happy Excelling!

Claire
==
 
Last edited:
Upvote 0
Re: Understanding this formula:=IF(TC[[#This Row],[Page]]="/","Home",IF(TC[[#This Row],[Page]]="/blog/","Blog Home",IF(ISNUMBER(SEARCH("/blog/category/",TC[[#This Row],[Page]])),"Blog Category&am

In theory, you should always end up with the right amount of closing brackets if you added them right after you add the opening bracket, but I don't think anybody does it that way.

I do, especially if I am putting a function INSIDE another. Function name, Open bracket, close bracket, then move left and add arguments. Saved my neck a few times! ;)
 
Last edited:
Upvote 0
Re: Understanding this formula:=IF(TC[[#This Row],[Page]]="/","Home",IF(TC[[#This Row],[Page]]="/blog/","Blog Home",IF(ISNUMBER(SEARCH("/blog/category/",TC[[#This Row],[Page]])),"Blog Category&am

Thank you everyone for helping me out with this :-)
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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