MicroStrategy ONE
ApplySimple
You can use the AppleSimple function to insert database-specific functions and simple operators directly into SQL. The ApplySimple function is used with simple operators and functions. This is a single-value function.
Syntax
ApplySimple()
Accepts facts, attributes, and metrics as input.
Example 1 Using an attribute
ApplySimple ("Datediff (YY, #0,getdate ())", [BIRTH_DATE])
Example 2 Using an attribute
ApplySimple ("Months_between (sysdate,#0)",[CURRENT_DT])
Example 3 Using a compound metric
You can use the "ApplySimple" function in a metric definition in order to calculate the greatest of a given number of values. The syntax is as follows:
ApplySimple ("Greatest (#0, #1, #2)", Metric_1, Metric_2,Metric_3)
Example 4
You need to display the values of Revenue that lie between 0 and 100,000 as "Low", between 100,001 and 200,000 as "Medium", and above 200,000 as "High." You can use the ApplySimple function in a metric definition as follows:
ApplySimple (" CASE WHEN #0 between 0 and 100000 THEN 'Low' WHEN #0 between 100001 and 200000 THEN 'Med' ELSE 'High' END ", Sum (Revenue){~})
Example 5 Rounding
You can use the ApplySimple function in a metric definition to round off the resulting values to a certain number of decimal places. In SQL Server, the syntax is as follows:
("ROUND (#0,1)", [M3])
where M3 is the metric and 1 is the number of decimal places to round to.
Example 6 CASE statement
You can implement an "If/Then" scenario by using ApplySimple. In the string below, M1=Max (Employee) and Dollar Sales is a metric.
ApplySimple ("CASE WHEN #0>10 THEN #1 ELSE '0' END", [M1], [DOLLAR SALES])