Functions Language

CaseStatement

The Case statement is an extension to the Quintessence language. The Case statement performs the same functionality as an IF statement, but is easier to read, particularly when there are many nested IFs in a statement. Depending on the value of an element, the Case statement transfers control to different statements within its body.

Syntax


Evaluating the value of a variable:

Case on <variable>

when <value> then <result>

[when <value> then <result> ‘]

[else <result>]

end

Evaluating the boolean value of an expression (true or false):

Case

when <expression> then <result>

[when <expression> then <result> ‘]

[else <result>]

end

Examples


Example 1. Using Case for a simple evaluation of an variable

Example 2. Using Case to evaluate an expression

Example 3. Using Case in Excel in a Quintessence function (Transform)

Example 1. Using Case for a simple evaluation of a variable


Case on Entity

when “5000” then “ABC Insurance Company”

when “5010” then “QQQ Retirement Fund”

when “5020” then “CBC Retirement Benefit Fund”

when “5030” then “Agri Provident Fund”

else “Unknown entity”

end

In this example, the equivalent IF statement would be:

IF(Code = “5000”, “ABC Insurance Company”, IF(Code = “5010”, “QQQ Retirement Fund”, IF(Code = “5020”, “CBC Retirement Benefit Fund”, IF(Code = “5030”, “Agri Provident Fund”, “Unknown entity”))))

This statement is much harder to read than the Case statement, and it is easy to make a mistake with the number of opening and closing brackets.

Example 2. Using Case to evaluate an expression


Case

when Entity = “5010” & TimeSeries = “Close Price” then “MarketDataProvider1”

when Entity = “5020” & TimeSeries = “EPS” then “StockExchange1”

when Entity = “5030” & TimeSeries = “DPS” then “PortfolioAdministrator1”

else “MarketDataProvider2”

end

In this example, the equivalent IF statement would be:

IF(Code = “5010” & TimeSeries = “Close Price”, “MarketDataProvider1”, IF(Code = “5020” & TimeSeries = “EPS”, “StockExchange1”, IF(Code = “5030” & TimeSeries = “DPS”, “PortfolioAdministrator1”, “MarketDataProvider2”)))

This statement is much harder to read than the Case statement, and it is easy to make a mistake with the number of opening and closing brackets.

Example 3. Using Case in Excel in a Quintessence function (Transform)


Range Calculate the fund name
5000 =Fx(Transform(A2:A6,”CASE When C1 = ‘5000’ then ‘ABC Insurance Company’ When C1 = ‘5010’ then ‘QQQ Retirement Fund’ When C1 = ‘5020’ then ‘CBC Retirement Benefit Fund’ When C1 = ‘5030’ then ‘Agri Provident Fund’ else ‘** UNKNOWN **’ end”))
5010
5020
5030
7788
Range Output
5000 ABC Insurance Company
5010 QQQ Retirement Fund
5020 CBC Retirement Benefit Fund
5030 Agri Provident Fund
7788 ** UNKNOWN **

Again, in this example, using a Case statement is much easier than using nested IF statements to achieve the same result.