Excel's SWITCH Function

Excel's SWITCH function is similar to Excel's IF and IFS functions and is the topic of this post. First, a review of the IF and IFS functions.

Users of Microsoft Excel may utilize the IF function to apply a logical test and if true return a result and if false return a different result. The IF function can apply mathematical operators and perform additional calculations. You can also nest multiple IF functions together in order to perform multiple comparisons.

The post Using Excel's IFS Function showed a case of using nested IF functions to determine the number of decimal places required to properly format price data.

The nested IF function:


Cell N2 in the sample available from the post calculated the number of decimal places using the RTD formula for Tick size (TSize):

=IF(LEN(RTD("cqg.rtd", ,"ContractData", "Tsize("&A2&")", "LastQuoteToday",,"T"))=1,0,LEN(RTD("cqg.rtd", ,"ContractData", "Tsize("&A2&")", "LastQuoteToday",,"T"))-2)

The goal was to allow the user to change the symbol in a cell, for example Cell A2, that was the symbol reference cell for other RTD formulas, such as Open, High, Low, and Close and not require the user to have to manually reformat the Open, High, Low, and Close cells to the proper number of decimals.

The IFS function was introduced as a method that avoids using nested IF functions and thus is a simpler format and easier to test:


The IFS function is available in the 2019 and Office 365 versions of Excel.

A simpler approach is available: The SWITCH function (introduced in Excel 2016).


The SWITCH function only requires one expression (the formula above is in cell N2) and then checks for the results and stops at the first true in the formula and returns that result.


Comparing the three functions:


The number of characters is 139, 112, and 94 respectively. Clearly, the SWITCH function would be easier to troubleshoot.

However, a popular form of nested IF functions include using And, Or, and Not, such as IF(AND()), IF(OR()), and IF(NOT(). These combinations do not work if you substitute SWITCH for IF.

The sample spreadsheet uses the SWITCH function to format prices in columns B through G using the TEXT function and the results of the SWITCH function from column O.


Columns N and O can be hidden.

The user can change any symbol and the prices will use the correct decimal formats.

Requirements: CQG Integrated Client or QTrader, and Excel 2016 (locally installed, not in the Cloud) or more recent.



Trading and investment carry a high level of risk, and CQG, Inc. does not make any recommendations for buying or selling any financial instruments. We offer educational information on ways to use our sophisticated CQG trading tools, but it is up to our customers and other readers to make their own trading and investment decisions or to consult with a registered investment advisor. The opinions expressed here are solely those of the author and do not reflect the opinions of CQG, Inc. or its affiliates.