<img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=8366258&amp;fmt=gif">
Skip to content

Evaluate With Date Functions in OBIEE

Think

by Kurt Wolff

If you’re not concerned about database portability – for example, you use Oracle and that’s that, forever – then the evaluate function in OBIEE can be useful. However, using the evaluate function can be tricky, and the documentation could be better.

Here’s an example of using Evaluate with the Oracle next_day function, which returns the date of the next specified day of the week following any given date. This function is useful for calculating the week ending date for any given date. If your standard week ends on Saturday, then the expression you would use would be next_day(<date>, ‘saturday’).  This is quite simple, but how do you use it within OBIEE?

Here’s a simple subject area in OBIEE which I used to test how to use next_day( ). It contains two logical tables: a Days table and a Facts table. The facts table shows how many calls occurred on any day.

OBIEE subject area logical tables Days and Facts with columns DATE1, DAYNAME, DAYOFWEEK, and CALLS

 

 

 

 

 

As these query results show, there is one call per day.

OBIEE analysis results showing daily calls by DATE1 with day name and day of week columns

 

 

 

 

 

 

 

The objective was to sum up the number of calls for each Saturday-ending week using the Oracle next_day function.

When you use the evaluate function in OBIEE, the expression builder presents you with this template:

OBIEE expression builder template for EVALUATE function showing strExpr and commaSeparatedExprs syntax

 

 

 

Following the template, you would write this:

OBIEE EVALUATE example using Oracle NEXT_DAY with column reference placeholders %1 and %2 for week ending date

 

However, this syntax produced a “Union of non-compatible types” error.

OBIEE Administration Tool error dialog showing nQSError 22027 union of non-compatible types using EVALUATE

 

 

 

 

 

I do not know what this error is really saying. Does the column name have to be enclosed in single quotes to make it a string?

OBIEE EVALUATE syntax using NEXT_DAY with fully qualified column in quotes that leads to SQL date conversion error

 

 

The administration tool accepts this, but you get a SQL error when you use it in a query.

ORA-01858: a non-numeric character was found where a numeric was expected

The reason is obvious when you look at the SQL generated:

select next_day('"XE".""."XE"."DAYS"."DATE1"','saturday') as C1
,sum(T3392.CALLS) as C2
from DAYS T3386
,DAYSCALLS T3392
where (T3386.id = T3392.id)
group by next_day('"XE".""."XE"."DAYS"."DATE1"','saturday')
order by C1

Instead of providing a column identifier that had a date data type as an argument in the next_day function, the SQL contained a string value.

My next thought when I encountered this was to include the column name as part of the first “str_Expr”.

OBIEE EVALUATE syntax using NEXT_DAY with fully qualified column in quotes that leads to SQL date conversion error

However, this produced another Oracle error:

ORA-01741: illegal zero-length identifier

So to fix this I edited the column identifier.

OBIEE EVALUATE passing column reference inside strExpr for NEXT_DAY function to calculate Saturday week ending date

 

The administration tool accepted this, but it produced a different SQL error at run time:

ORA-00904: "DAYS"."DATE1": invalid identifier

The reason this is an invalid identifier is that the SQL OBIEE generated included a table alias for the DAYS table, T3392.

select next_day("DAYS"."DATE1",'saturday') as C1
,sum(T3392.CALLS) as C2
from DAYS T3386
,DAYSCALLS T3392
where (T3386.id = T3392.id)
group by next_day("DAYS"."DATE1",'saturday')
order by C1

To fix this, I deleted the DAYS identifier in the function. This might work, but not if you have a DATE1 column defined in more than one table in the FROM clause. This data contained a DATE1 column both in the DAYS table and DAYSCALLS table. Therefore, the query produced another Oracle error.

ORA-00918: column ambiguously defined

To fix this, a table identifier was needed. Since OBIEE used T3386, I included this in the evaluate function.

OBIEE EVALUATE using table alias T3386 with DATE1 to avoid invalid identifier and ambiguity errors in generated SQL

 

The administration tool accepted this, and OBIEE generated correct SQL that Oracle accepted.

select next_day("T3386"."DATE1",'saturday') as C1
,sum(T3392.CALLS) as C2
from DAYS T3386
,DAYSCALLS T3392
where (T3386.id = T3392.id)
group by next_day("T3386"."DATE1",'saturday')
order by C1

However, the results in Answers were not correct.

OBIEE results showing Week Ending displayed incorrectly as text (YYYYWW style) after EVALUATE NEXT_DAY

 

 

 

 

 

 

 

Notice that instead of getting a week ending date, we see something that looks like a month, with the sum by week presented as separate rows within the month. Even though the function next_day returns a date, OBIEE treated it as text.

OBIEE logical column properties showing Week Ending data type set to CHAR causing date to be treated as text

 

 

 

To fix this, I added AS DATE in the formula to declare that the returned value was a date.

OBIEE logical column data type set to DATE with EVALUATE NEXT_DAY expression cast AS DATE for correct date handling

 

 

 

 

After I refreshed metadata on the presentation server, the query now produced the desired results.

OBIEE analysis results showing correct Week Ending dates after casting EVALUATE expression as DATE

 

 

 

 

 

 

 

Looking at column properties, everything seemed correct. The column was being treated as a date.

OBIEE column properties showing date format settings under Data Format tab for Week Ending

 

 

 

But look what happened – see the X axis -- when I graphed this.  The X-axis showed question marks instead of week ending dates.

OBIEE line graph showing Week Ending x-axis displayed as question marks when column reverts to text datatype

 

 

 

 

 

After adding the graph, I examined the column properties.

OBIEE column properties showing Treat Text As plain text indicating Week Ending column reverted to text

 

 

 

 

The column had reverted to text!

To get OBIEE to recognize the results of the evaluate function as a date, one solution that seemed to work was to use the Oracle to_date function along with the next_day function.

OBIEE EVALUATE using TO_DATE and NEXT_DAY to force week ending value to be recognized as a DATE for graphing

 

Now the graph showed week ending dates on the x-axis.

OBIEE line chart with Week Ending dates correctly displayed on x-axis after using TO_DATE with NEXT_DAY in EVALUATE

 

 

 

 

 

 

 

 

 

Comments

Comments not added yet!

Your future starts today. Ready?

kpi-top-up-button