Oracle Analytics Cloud and Server

Welcome to the Oracle Analytics Community: Please complete your User Profile and upload your Profile Picture

OBIEE AGO function for 1 month prior

Received Response
1746
Views
6
Comments
user4109719
user4109719 Rank 4 - Community Specialist

In OBIEE, I am trying to get a measure for the previous and current months on the same line.  I'm using the AGO function to get the previous month measure.  It works fine if I use a single day as the grain but the monthly results don't make any sense.  I'm using this expression to get the month:

TIMESTAMPADD(SQL_TSI_DAY, -1*(DAYOFMONTH("- Invoice Date"."Date - Invoice" )-1) , "- Invoice Date"."Date - Invoice" )

This is to get the Prior Month Sales

AGO("Measures - Invoiced Sales"."Net Sales - Products and Services",1)

These are the results starting 1/1/2017.  The results are not even close to correct.  I can't figure out what it's doing.  For 4/1/2017 the values are identical for some reason. 

              

MonthNet Sales - Products and ServicesPrior Net Sales - Products and Services
1/1/2017241584.80224838.84
2/1/2017219997.2916745.96
3/1/2017268049.85251091.32
4/1/201714951961.7314951961.73
5/1/201717301172.5816255156.18
6/1/201716900342.801046016.40
7/1/201715655569.48702392.04
8/1/201716997174.82832775.94
9/1/201717516351.2817516342.38
10/1/201718943948.558.90
11/1/201718466469.431001084.96
12/1/201717601620.0217600106.96
1/1/201819183573.2218258195.81
2/1/201816925629.5015949988.17
3/1/201818051468.24975641.33
4/1/201817696257.1316842232.22
5/1/201818674737.5917818018.33
6/1/201817415379.8017414595.93
7/1/201818210969.0517243750.77
8/1/201819705728.7518896268.76
9/1/201816641547.06809459.99
10/1/201819764379.0718903093.53
11/1/201817758578.8617043570.38
12/1/201817457314.2116468831.00
1/1/201918992934.9318275014.95
2/1/201916674484.18717919.98
3/1/201917713099.2717710879.05
4/1/201919152519.322220.22
5/1/201913781477.591023824.42

Thanks.

Tagged:

Answers

  • Hi,

    Not sure what you use the TIMESTAMPADD... thing for, AGO doesn't require a date, it works based on the time of the "row".

    AGO doesn't do any blackmagic, it's purely a SQL way to get data from the previous period based. It uses your data and model to get results.

    If you model is wrong (or at least not fully correct) AGO could give you weird results just because it can't imagine the shortcut you maybe did in your RPD.

    Look at the generated physical SQL, look at what logic it's applying and there you find what are the numbers it returns.

    It will help you highlight RPD shortcuts or modelling shortcuts or "options" you adopted which prevent AGO to work directly and will require you some fixes first.

  • Christian Berg-0racle
    Christian Berg-0racle Rank 10 - Analytics Guru

    @Gianni Ceresa I posted something similar last week but deleted it.

    For the life of me I can't figure out why everybody insists on mindlessly writing code instead of reading about....two questions in here, seeing that code isn't the answer and trying to comprehend how the tool actually works. I had the impression we had explained that about 10 times this last quarter and about 20 times this year so far.

  • user4109719
    user4109719 Rank 4 - Community Specialist

    I didn't explain things well.  The AGO function returns correct results when I use a single day: 

      

    DateNet Sales - Products and ServicesPrior Net Sales - Products and Services
    1/1/20170.00
    1/3/201756730.21
    1/4/201752892.9656730.21
    1/5/201744246.5752892.96
    1/6/201731256.8344246.57
    1/7/201731256.83
    1/9/201755139.29
    1/10/201760956.0955139.29
    1/11/201754924.5160956.09
    1/12/201758634.5354924.51
    1/13/201713765.4958634.53
    1/14/201713765.49
    1/15/20170.00
    1/16/201773381.440.00

    The field that produced the date in the first column here is - Invoice Date"."Date - Invoice", which comes from a date dimension joined to the fact table.  The second column is the measure "Measures - Invoiced Sales"."Net Sales - Products and Services" from the fact table, and the third column is the AGO function: AGO("Measures - Invoiced Sales"."Net Sales - Products and Services",1).

    All I am using the TIMESTAMPADD function for is to get the results by the first of the month.  The date dimension doesn't have a first of the month date stored in it.  I am not feeding it into the AGO function, it's to produce a column in the table.   When I replace  - Invoice Date"."Date - Invoice" with the TIMESTAMPADD function I get the first set of results in my original question, which obviously aren't correct.

  • Ok, in all your examples you posted the AGO function is used wrongly. The syntax is:

    AGO(<measure_expression>, <level>, <number of period>)

    You don't seem to have a <level> anywhere in what you posted so far.

    If you want AGO to work at the month level, you need to tell the system to do so.

  • user4109719
    user4109719 Rank 4 - Community Specialist

    I am trying to use the overloaded AGO function which only takes 2 inputs: 

    there is a overloaded version of AGO:  AGO(expr, offset) which uses the grain of the Answers query as the level.

    As I understand it, this is supposed to detect the grain from the field being used to generate the time period.  It works when using a single day.  I can't get it to work with a year either.  It produces blanks in the 1 year ago column.

  • user4109719 wrote:...supposed to detect the grain from the field being used ...

    Every time you let the system do something supposing it works as designed, be ready for surprises (been there, done that, concluded it's good to suppose but it's safer to be sure ).

    The grain of the analysis is generally identified based on the granularity of the time dimension columns you use. The problem is that often the grain is way more detailed than what you had in mind for various reasons.

    So do you really need a single analysis jumping around on various levels? Or you look for a fixed level and in that case it's safer to set it in the function so the behaviour is constant and predictable?