Skip to main content

Applycomparison advancd filter with a select statement

ApplyComparison ("#0 >= (select max(Hour)-1 from FACTTABLE where DAYDATE = current_date)", Hour@ID)
MicroStrategyā€™s strongest feature is itā€™s SQL Engine. The ability to define object relationships and then allow MicroStrategy to generate all of the appropriate SQL as you manipulate and drill is the core of the product. But of course, it canā€™t handle every since situation and you may sometimes need to help it along in certain instances. To extend this flexibility to you, MicroStrategy offers 5 functions which allow you to directly supply the SQL you want for a specific piece of the Query: ApplySimpleApplyAggApplyComparisonApplyOLAP and ApplyLogical. Today, Iā€™ll talk about ApplyComparison, which allows you to provide custom SQL in the WHERE clause of the query.
Example Scenario

Say that you have a report that should compare Units Sold for Today vs Yesterday by Hour. If you were to build this report by simply adding the Hour attribute and two Conditional Metrics for Today Units Sold and Yesterday Units Sold, youā€™d end up with a graph like this:
external image tvy1.gifFictitious Data
Itā€™s a nice picture of how the days are comparing, but itā€™s a little ugly since we donā€™t have data for 7am and ahead for today yet. Ideally, weā€™d like to filter off the data for Today that we havenā€™t received, but how do we know where we are? Assuming that we arenā€™t strictly real time and canā€™t assume based on the current time, weā€™d want to check the max Hour that exists in the table, and then go up to that minus 1. We could probably build that with some different types of metrics or a Report as Filter, but Iā€™ll choose to do this using an ApplyComparison.
Before you start

First of all, you can only build this kind of filter in Desktop (so, not Web). You also need to enable the feature in Desktop, as itā€™s not available be default. Go to Tools->My Preferences->Filters and check the box for Show Advanced Qualifications. This will enable the option to use ApplyComparisonā€™s in Filters.
Back to the Report

Double click on your Report Filter and youā€™ll now have the option to add an Advanced Qualification:
external image tvy4.gif
You can then provide the code for the ApplyComparison. The code you provide will go into the WHERE clause, and you can pass attribute values using the #n syntax, where n is the zero based number of parameters youā€™re passing. In my example, Iā€™m passing a single parameter, so itā€™s #0. I could pass additional values by also including #1, #2, etc in my code if I needed them. Also note that when you provide the value at the end of the statement, itā€™s in the format Hour@ID, not just Hour. MicroStrategy changes the display of it slightly in my screenshot to Hour (ID), but the actual code youā€™ll be using looks like this:
ApplyComparison ("#0 >= (select max(Hour)-1 from FACTTABLE where DAYDATE = current_date)", Hour@ID)
external image tvy3.gif
And now the graph looks nice and clean:

external image tvy2-300x170.pngFictitious Data
BONUS TIP

Another way to accomplish this using ApplySimple instead of ApplyComparison would be to drag the Hour attribute to the Report Filter like normal, choose ID as the form and Greater Than or Equal To as the operator, and choose Custom from the drop down box and provide the ApplySimple code:
external image tvy5.gif
ApplySimple("(select max(Hour)-1 from FACTTABLE where DAYDATE = current_date)", 0)

Since weā€™re not including any parameters for this query, we can use 0 as the placeholder at the end to satisfy the functionā€™s parameters.
This will generate the same SQL and results, but without needing to enable the Advanced Qualification option which could be confusing to some.

ApplyComparison("#0<=(select to_number(to_char(add_months(sysdate(),-1), 'yyyymm'))) ",[Instance Month]@ID)

Worked example:
select distinct a11.month_sid
from mstr_datamart.date_dim a11
where a11.date_sid<=(select to_number(to_char(add_months(sysdate(),-1), 'yyyymmDD'))) and a11.date_sid>=(select min(utc_date_sid) from mstr_datamart.ox_transaction_sum_daily_fact)
order by 1 desc

ApplyComparison("#0<=(select to_number(to_char(add_months(sysdate(),-1), 'yyyymmDD'))) and #0>=(select min(utc_date_sid) from mstr_datamart.ox_transaction_sum_daily_fact order by 1 desc)",[UTC Date]@ID)

Comments

Popular posts from this blog

MicroStrategy URL API Parameters

MicroStrategy URL Structure The following table summarizes the root URL structure used for every request to MicroStrategy Web. Environment Main Application URL Administration URL J2EE http://webserver/MicroStrategy/servlet/mstrWeb http://webserver/MicroStrategy/servlet/mstrWebAdmin .NET http://webserver/MicroStrategy/asp/Main.aspx http://webserver/MicroStrategy/asp/Admin.aspx Every request sent to MicroStrategy Web calls a central controller. Parameters are appended to  Main.aspx  or  mstrWeb  (in a .NET and J2EE environment, respectively) to indicate to the controller how the request should be internally forwarded and handled. The following examples show a URL for accessing a MicroStrategy folder when the user does not have an existing session. The URL contains not only the parameters needed to connect to MicroStrategy Web, but also the parameters needed to log on and create a session. J2EE environment: <a href="http:...

Microstrategy "Error type: Odbc error. Odbc operation attempted

 "Error type: Odbc error. Odbc operation attempted: SQLExecDirect. [HYT00:0: on SQLHANDLE] [MicroStrategy][ODBC Oracle Wire Protocol driver]Timeout expired" is shown when executing reports from Web When users are trying to execute some reports in MicroStrategy web in particular, they may receive the Error ā€œSQL Generation Complete Index out of rangeā€ and ā€œTimeout expiredā€ error as shown below: Possible Causes: One possible cause is that the MicroStrategy Intelligence Server using a cached database connection that was already dropped by the RDBMS. To resolve this: Admin should delete the database connection caches and create a new DSNs in case they are sharing DSNs to connect to different databases. In addition, change the settings for the ā€˜Connection lifetimeā€™ and the ā€˜Connection idle time outā€™.  Follow the steps below to perform the mentioned changes and verify the report after each step and some of the settings require i-server r...

Case functions Microstrategy

Ca se functions Microstrategy Case functions return specified data in a SQL query based on the evaluation of user-defined conditions. In general, a user specifies a list of conditions and corresponding return values. Case This function evaluates multiple expressions until a condition is determined to be true, then returns a corresponding value. If all conditions are false, a default value is returned.  Case  can be used for categorizing data based on multiple conditions. This is a single-value function. Syntax Case ( Condition1 ,  ReturnValue1 ,  Condition2 , ReturnValue2 ,...,  DefaultValue ) Example Case(([Total Revenue] < 300000), 0, ([Total Revenue] < 600000), 1, 2) sum(Case (Day@DESC in (ā€œSatā€,ā€Sunā€), Sales, 0) {~+} Sum(Case(Category@DESC In("Books","Electronics"),Revenue,0)){~+} CaseV (case vector) CaseV  evaluates a single metric and returns different values according to the results. It can be used to perfo...

Microstrategy Custom number formatting symbols

Custom number formatting symbols If none of the built-in number formats meet your needs, you can create your own custom format in the Number tab of the Format Cells dialog box. Select  Custom  as the Category and create the format using the number format symbols listed in the table below. Each custom format can have up to four optional sections, one each for: Positive numbers Negative numbers Zeros Text Each section is optional. Separate the sections by semicolons, as shown in the example below: #,###;(#,###);0;"Error: Entry must be numeric" For more examples, see  Custom number formatting examples . To jump to a section of the formatting symbol table, click one of the following: Numeric symbols Character/text symbols Date and time symbols Text color symbols Currency symbols Conditional symbols Numeric symbols For details on how numeric symbols apply to the Big Decimal data type, refer to the  Project Design Guide . ...

Microstrategy Dossiers explained

Microstrategy  Dossiers With the release of MicroStrategy 10.9, weā€™ve taken a leap forward in our dashboarding capabilities by simplifying the user experience, adding storytelling, and collaboration.MSTR has  evolved dashboards to the point that they are more than dashboards - they are  interactive, collaborative analytic stories . Ultimately, it was time to go beyond dashboards, both in concept and in name, and so  the've  renamed VI dashboards to  ā€˜ dossiers ā€™.  Dossiers can be created by using the new Desktop product or Workstation or simply from the Web interface which replaces Visual Insights. All the existing visual Insights dashboards will be converted to Dossiers   With MicroStrategy 10.9, there was an active focus on making it easier to build dashboards for the widest audience of end users. To achieve this, some key new capabilities were added that make it easier to author, read, interact and collaborate on dashboards ...

Update the data on an Intelligent Cube without having to republish the entire cube in MicroStrategy

Update the data on an Intelligent Cube without having to republish the entire cube in MicroStrategy MicroStrategy has introduced a feature known as, Incremental Refresh Options, which allow Intelligent Cubes to be updated based on one or more attributes, by setting up incremental refresh settings to update the Intelligent Cube with only new data. This can reduce the time and system resources necessary to update the Intelligent Cube periodically versus a full republish. For example, if a user has an Intelligent Cube that contains weekly sales data, the user may want this Intelligent Cube to be updated at the end of every week with the sales data for that week. By setting up incremental refresh settings, he can make it so that only data for one week is added to the Intelligent Cube, without affecting the existing data and without having to reload all existing data. Users can select t...

Microstrategy Dashboard performance improvements steps

Microstrategy  Dashboard performance improvements steps: Many times, causes of poor performance can be simplified to specific components. To troubleshoot performance issues, users must identify these components, then make the appropriate modifications to the environment and/or to the MicroStrategy dashboard to reduce bottlenecks. Dashboard execution stages can be represented below: MicroStrategy Intelligence Server When an end user makes a  Document Execution Request  through any client (a web browser via MicroStrategy Web, the MicroStrategy Desktop/Developer client, the MicroStrategy Mobile app, or the MicroStrategy Office client), the request is sent to the MicroStrategy Intelligence Server, which processes the request and prepares the response. The MicroStrategy Intelligence Server will execute all children datasets on the dashboard by either generating SQL and running this against the data warehouse, or by fetching data from a cache. The Inte...

Microstrategy Authentication Using the URL API

Microstrategy Authentication Using the URL API Users have to be authenticated before accessing functionality in MicroStrategy Web. Using the URL API, there are three ways for MicroStrategy Web to obtain the information needed to authenticate a user. Opening the login page to gather user for credentials    Bypassing the login page by providing credentials in the URL    Bypassing the login page by providing the session state in the URL A detailed explanation of each method for obtaining the authentication information is provided below. Opening the login page to gather user for credentials If the URL attempts to access a MicroStrategy Web page that requires login and no credentials or session state are provided in the URL, the user is redirected to the login page. If login is successful, the user is redirected to the specified page.   The sample URL shown below executes a report without providing authenticating information. Since the Repo...

Prompt-in-prompt(Nested Prompts) in Microstrategy

Prompt-in-prompt(Nested Prompts) in  Microstrategy Nested prompts allows you to create one prompt based on the other and other bases on another, nested prompts allows us to prompt the highest level(Like year) to middle level(like Quarter, then to the low level(like Month). Here you can see how to  create a 3-level deep nested prompt that will prompt the user to select a year, then a quarter within that year, then a month within that quarter. Prompt-in-prompt is a feature in which the answer to one prompt is used to define another prompt. This feature is only implemented for element list prompts . The following procedure describes how to achieve this: Create the highest level filter. This is a filter which contains a prompt on an attribute element list. Create a filter on the attribute "Year." Click "prompt on attribute element list" and click "Next" through the rest of the screens to accept the default values. Do not set any additio...

Multi-Table Data Import(MTDI) from one or more supported data sources

Multi-Table Data Import(MTDI) from one or more supported data sources In MicroStrategy Analytics Enterprise Web 10 onewards, users can now simultaneously import two or more tables from one or more supported data sources, this feature is called Multi-Table Data Import (MTDI) which has been renamed as Super Cubes in MSTR 2019 (Does it sound like multisourcing for all the users without admin help?) Currently, all connectors in MicroStrategy Web 10 except " OLAP " and " Search Engine Indices " support Multi-Table Data Import. Users are able to add multiple tables/files when doing data import from single connector, as shown below: Users are also able to combine multiple tables/files from different sources and store them into one single Intelligent Cube, as shown below: