You are on page 1of 18

OBIEE Repository Variables, Filtering and Conditional Formatting by Mark Rittman

Im currently sitting in Galway airport coming back from a few days work, and as Ive got an hour or so free I thought Id take a look at server variables in OBIEE. Repository and Session server variables are something you tend to encounter first when working with LDAP security, but they can also be used to create dynamic row-level filters, provide the filter values for conditional formatting and many other tasks, and its worth taking a few minutes to understand how they work. Variables in the Oracle BI Server can be either repository or session variables, and are defined using the Variable Manager within the Oracle BI Administrator (Manage > Variables).

This brings up the Variable Manager, that divides variables out into repository and session variables, with a further subdivision into static and dynamic repository ones and system and nonsystem session ones. You can also define variables at the Presentation Server level, these are scoped to individual dashboards and are used amongst other things for setting dashboard prompt values and integrating the dashboard with BI Publisher parameters. Heres a screenshot of a typical Variable Manager screen.

So what are server (repository) variables used for? Well if youve done any programming, either in languages like Visual Basic or on the web, variables these platforms use are the same as the ones that the BI Server uses. As with web development, you can either have server variables that hold the same value across all sessions (in BI Server terms, a repository variable), or variables that hold a value specific to each user session (session variables in the BI Server). Furthermore, repository variables can either be constants (static repository variables) or can have values that vary over time (dynamic repository variables), with the dynamic ones refreshed to a schedule via SQL calls and session variables usually set at the time of logon by reference to an LDAP server or an SQL statement. So now thats all clear, in what sort of situation would they be used? Heres a scenario that makes use of all these types of BI Server variable. We have a reporting requirement where salespeople are responsible for a number of states, and these states change on a constant basis. Some of these states are shared with other salespeople and its not really practical to define set groupings of these states, hence we have a lookup table on our database that lists out the states each salesperson is responsible for, together with a marker against one particular state that is their home state. We want to use these lists of states as dynamic filters on the reports our salespeople run, and have reports default to their home state when they view their data in a dashboard. We also want to only show data for the current month in their reports, and hold the state in which our headquarters is based in a constant so that we can highlight the sales that are made near to it. In other words, weve got a good example of where variables in various shapes and forms can be used to make this process a whole lot easier to implement. To start off, I use the Variable Manager to define a new static repository variable that I call HEAD_OFFICE_STATE and set to the value NY. This initial value, that stays constant for

static repository variables, is called the default initializer and can either be typed in or set via an expression. The only way this variable value can change is if I go back into the Variable Manager and change it there.

Next I create the second repository variable, this time a dynamic one, that is used to return the current month name and year to any query that requires it. Unlike static repository variables this variables values change over time, using an SQL statement executed to a schedule to update its values.

As well as having a default initializer, dynamic variables get their values from initialization blocks that provide the mechanism to execute the SQL via a schedule. To define the initialization block I press New and enter the SQL, refresh frequency and variable target for the block. Notice in this example that Im running the SQL against an Oracle database connection pool, and the truncated month and year name is generated through some Oracle function names and a reference to sysdate.

So now Ive got my two repository variables defined. Before I create my my session variable, I first have to locate a table in my database that lists out the selection of states that each salesperson is working with. Notice how theres sometimes more than one row per salesperson.

I now move on to creating the session variable. To use the data from the table above to provide the values for my dynamic filter, I first of all make sure that this table is accessible through a connection pool in the BI Server physical layer, and then go back to the Variable Manager to define my session variable. Now if this variable was going to hold a single, scalar value, I could define it as a regular non-system session variable, but as it need to hold data from more than one database row, I instead define it using an Initialization Block and row-wise variable initialization, which defines one or more variables based on a select statement, dynamically creating the variables as needed and concatenating the results of multiple rows into the variable. To perform this task I first define a the new Initialization Block and call it STATE_SECURITY. I then define my SELECT statement as the following:
select 'STATE_FILTER',state from variable_example.salesperson where salesperson_name = ':USER'

This will return one or more rows with STATE_FILTER, the new dynamically-created variable name, as the first column, and the set of allowed salesman states as the second value, filtered on the logged-in user ID. My initialization block now looks like this:

To assign the results of this SELECT statement to a variable, the STATE_FILTER variable, I then click on the Edit Data Target button and select Row-Wise Initialization, rather than try and assign the results to individual variables. The initialization block will then take all the rows that have STATE_FILTER as the first column and create a single concatenated, commaseparated list out of the second column, so that I can then apply this value to a filter.

Now that the session variable definition is complete, I move over to the Security Manager application, create a group for all of my report users and then define a filter for that group against the SALES table, the one I want to restrict access to. The filter references the session variable I just created, using an equality (=) operator rather than the in operator youd have expected, this is a requirement for row-wise variables and OBIEE handles the translation properly in the background.

Now if one of the affected users logs in an runs a report against that table, the results are filtered down without any intervention on their part.

Conditionally formatting the State column based on whether the value each row contains is also fairly straightforward. When you create a conditional format condition you can specify that that value tested against is a variable; to access one of the repository variables you put biServer.variables[''] around the variable name so that, in my example, the variable name becomes biServer.variables['HEAD_OFFICE_STATE'].

Displaying the report now shows all instances of NY highlighted in red, based on my conditional formatting rule and the value of the HOME_OFFICE_STATE static repository variable.

So there you have it. Moving on from here, filtering the report again based on the dynamic repository variable is just a case of referencing the CURRENT_MONTH variable in my filter, and adding another session variable to hold the salespersons home state involves creating another initialization block that this time provides a value for a regular (i.e. not row-wise) HOME_STATE session variable. in Share 0 Posted in Oracle BI Suite EE | 21 Comments

Comments

1. Osman Says: September 4th, 2008 at 10:26 am Thank you for the explanation, but this means that you should maintain a table with the salespersons and the STATE, but is it also possible to do this for a group in stead of user? 2. Mark Rittman Says: September 5th, 2008 at 7:28 am @Osman Do you mean, is it possible to set up a dynamic filter based on groups rather than user? Yes is the answer, obviously groups dont have sessions and therefore their own session variables, what Id probably do is set up a dynamic system variable that refreshes, say, every day or every hour, have that hold the list of states assigned to each group, and then set up group filters that reference these dynamic system variables. regards, Mark 3. Sarosh Says: September 8th, 2008 at 6:38 pm Hi Mark, I am conditionally formatting negative values in a column based on a simple filter test for column values less than zero. However, I do have total (summary) rows in the table (and pivot table) and could not find any way to conditionally format the values in them. So, while the negative values in the column display in red, the toal displays in black even though it is negative! Do you know of any workaround to this? Thanks, Sarosh 4. Vijaya Says: September 9th, 2008 at 6:47 pm Hi Mark,

I have an OBIEE Dashboard request that has 7 pivot tables and depending on the day of the week, we need to automatically default to a specific pivot table. Is there any way in OBIEE to dynamically default to a specific pivot table based on a condition? Will appreciate any input on this issue. Vijaya 5. Sarosh Says: September 9th, 2008 at 11:26 pm Hi Mark, I encountered an issue with Oracle BI EE Session Variables that Id appreciate your opinion on. I have two sources from where I could get the Company information for a user LDAP or an external SQL Server table. SourceA is the default from an LDAP source, and SourceB may exist in the external table, and if it does exist then it should override SourceA. So I set up SourceA as a Session variable to get the company LDAP attribute in an initialization block works just fine. Set up SourceB as SELECT COMPANY FROM USER_TABLE WHERE USERID = :USER in another initialization block. Works fine by itself. To get the values conditionally, I tried the following for SourceB: SELECT ISNULL((SELECT COMPANY FROM USER_TABLE WHERE USERID = :USER), :SourceA). This works fine so long as SourceB is present, but if it returns NULL from the external table, then the value of :SourceA is not assigned to SourceB. It seems that :User and :Password are the only session variables that can be referred to in initialization blocks. This seems to be a perplexing limitation. Thanks, Sarosh 6. Peter Scott Says: September 10th, 2008 at 1:28 pm @Sarosh Have you tried to prefix the name sourceA with NQ_SESSION. eg NQ_SESSION.SourceA?

Also if you are using multiple initialization blocks make sure that the blocks execute in the correct dependency order. 7. Sai Kumar Reddiboyina Says: September 11th, 2008 at 1:17 pm Hi everyone, i have an issue with one of the requests The Subject Area Sales has Columns Report Date and Sales Facts Sales (Subject Area) Report Date (Column1) Date Day Ago Date Week Ago Date Month Ago Date Sales Facts (Column2) Gross Sales Day Ago Gross Sales Week Ago Gross Sales Month Ago Gross Sales The Request is to see the Date, Gross Sales, any one Historic Gross Sales (Day Ago or Week Ago or Month Ago) and the Historic Date. I created the answer request with a column selector on the Day Ago Gross Sales and added Week Ago Gross Sales and Month Ago Agross Sales as items in the selector Request: Column Selector: Prior PeriodDay Ago Gross Sales DateGross Sales Day Ago Gross SalesHistoric Date 9/1/2008$100$150???????? 9/2/2008$99-$89-???????? 9/3/2008$35-$22-???????? The Column Selector works great.(AKA, when I select Prior Period as Week Ago Gross Sales, I get the Date, Gross Sales and Week Ago Gross Sales as expected.

Issue: How would I get the Historic Date, dynamically based on the Column Selector? ex: 1. When the column Selector, Prior Period = Day Ago Gross Sales Then I would like to see the Day Ago Dates under the Historic Date bucket 2. When the column Selector, Prior Period = Week Ago Gross Sales Then I would like to see the Week Ago Dates under the Historic Date bucket. and so on Can any one please help me how do i link the Historic Gross Sales with the Historic Dates Please let me know if the above situation is not explained well and I will try to give more inputs. Any help is greatly appreciated. Thanks Sai 8. Sarosh Says: September 11th, 2008 at 4:57 pm Hi Peter, Tried every conceivable way to reference the session variable, but it just does not seem to work. Yes, the initialization blocks are in the correct order SourceA is initialized before SourceB. Thanks, Sarosh 9. Peter Scott Says: September 11th, 2008 at 7:15 pm @Sarosh Try using VALUEOF(NQ_SESSION.SourceA) 10. Sarosh Says: September 12th, 2008 at 4:53 pm Hi Peter,

Tried VALUEOF as well. I think all these expressions (Valueof, NQ_SESSION) are meant to be used in Answers only, not in the repository. I tried substituting :USER and :PASSWORD in the ISNULL statement in the Init Block and they are the only repository variables that could be properly substituted in the ISNULL statement. Very strange! Anyway, we did a workaround through external database tables, creating one table for each Company, and populating each table with the users from their respective companies. Klunky, but works. Thanks for all your help. 11. Peter Scott Says: September 12th, 2008 at 5:26 pm You should be able to use session variables in the RPD it is documented or at least quoted in an example see also http://blogs.oracle.com/siebelessentials/2008/09/#005980 which was posted earlier today where there is a handy guide to variable use which shows me that I should have used double quotes; but that differs from the manual page that has single quotes around the whole ValueOf() expression But also remember that you can only define a session variable in one block you cant redefine in a second block 12. Vijay Says: October 30th, 2008 at 8:56 pm Hi Thanks for this blog. Would request your help to resolve my issue. I have to call a function with varchar parameters. parameter are nothing but my table column values.Ive created session variables which holds value from my table column values. for eg: *EVALUATE(REP1_FIRSTMONTH_F(%1) AS CHARACTER ( 30 ), VALUEOF (NQ_SESSION.month))* so whenever i call function using EVALUATE in OBIEE. i hve to pass (single quotes) for my varchar values. without this , im facing error stating : *State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A

general error has occurred. [nQSError: 59015] The requested column PERIOD0 does not exist in this table. (HY000)* If ill give parameter within single quotes in my dashboard prompt( by entering manually) it is working fine, but fails without the quotes. I tried giving VALUEOF(NQ_SESSION.sess_Var) wthin quotes, but couldnt get resolved. kindly help me in solving this issue. Thanks for your time Regards Vijay 13. Kelly Says: November 4th, 2008 at 8:43 pm Maybe a simple questions but has anyone gotten Dynamic Variables refreshed on Unix and if so how? Admin Guide says You will also set up a schedule that the Oracle BI Server will follow to execute the query and periodically refresh the value of the variable. 14. Peter Scott Says: November 6th, 2008 at 9:14 pm @Kelly Dynamic repository variables require the Oracle BI Scheduler there is some documentation on how to set this up on Unix in the Infrastructure installation and configuration guide. You will need to create some tables (using the scripts supplied) for the scheduler repository see the systems requirements and support platforms guide for acceptable databases for this Oracle is OK though :-) When installed make sure that the schedule administrator user has administrator rights to the RPD file If you have any more questions just ask 15. Allwin Says: December 4th, 2008 at 9:49 am Can anyone suggest the usage of Request Variable in OBIEE. I couldnt find any documentation on this.

16. Pankaj Nakil Says: March 5th, 2009 at 8:20 am Hi, Is there any weay we can pass multiple selected values in to a request variable on UI to a session variable? Its seen once we select Multiselect option we cant set a variable. Any workaround on this? Thanks, pankaj 17. Rama Says: April 24th, 2009 at 10:16 pm Hi, This article was great. If I have SALESMAN, STATE table AS MARK MI;FL;MA, will the above filter applies? The only change I made to your table is, instead of having separate records for a single sales person working in different states I concatenated all the states a salesman operates separated by a semicolon, thus having single record for each salesperson Will this technique works? Thanks in advance. rama 18. PLABAN MISHRA Says: April 29th, 2009 at 7:32 am I would like to know about cache management in a clustering environment. 19. Mohamed Adel Says: December 22nd, 2009 at 8:49 am

I tried the same approach used in STATE_FILTER example. I created an initialization block as follows: select DISTINCT USER_REGION, W_USER_PROFILES.REGION from W_USER_PROFILES WHERE W_USER_PROFILES.USERNAME = :USER the table W_USER_PROFILES contains all regions, cities that can be accessed by each user. When i tested the initialization block values it was displayed properly. I added filter to one user i.e. Location.Region = VALUEOF(NQ_SESSION.USER_GROUP). But when i logged in and seelcted column Region in an answer all regions were displayed. When i used this session variable by adding filter to the Region column in the in the answer, It worked properly. Any idea? 20. SRIDHAR Says: April 20th, 2011 at 6:16 am when we are using row wise initialization for dataleval securityIs there any limitation on data or no.of users in the external table. 21. Pradeep Says: December 9th, 2011 at 11:32 am I have a production issue,where the user is asking his id to be added as one of the recipient to an Ibot. How can we retrieve all the ibots that have been configured logging in as an AdminI tried seraching by the name in the search box provided, but cud not..I wud like to knw by logging in as admin do we hav acces to all ibots configured for specfic userspls help

You might also like