Oracle Analytics Cloud and Server

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

Previous quarter value in variable

Received Response
233
Views
54
Comments
3612030
3612030 Rank 3 - Community Apprentice

Hello!

How to do a proper calculation to get a previous quarter value using passed presentation variable? I have @{Quarter} in my prompt which passes a quarter for "Sales - CRM Pipeline"."Time".Enterprise Quarter" and then using this variable I want to get a previous quarter for

"Sales - CRM Historical Pipeline"."Pipeline Snapshot Date"."Pipeline Snapshot Enterprise Quarter". And for this im using:

CASE WHEN  RIGHT('@{QUARTER}', 1) = '1'  THEN CAST(CAST(LEFT('@{QUARTER}', 4) AS INTEGER) -1 AS CHAR)||' '||'Q'||' '||'4' ELSE CAST(CAST(LEFT('@{QUARTER}', 4) AS INTEGER) AS CHAR)||' '||'Q'||' '||CAST(CAST(RIGHT('@{QUARTER}',1) AS INTEGER)-1 AS CHAR) END

and it gives me a proper calculated result (for example 2017 Q4 if @QUARTER is 2018 Q1)

But then when I try to use it in my filter like that:

"Pipeline Snapshot Date"."Pipeline Snapshot Enterprise Quarter" IN (CASE WHEN  RIGHT('@{QUARTER}', 1) = '1'  THEN CAST(CAST(LEFT('@{QUARTER}', 4) AS INTEGER) -1 AS CHAR)||' '||'Q'||' '||'4' ELSE CAST(CAST(LEFT('@{QUARTER}', 4) AS INTEGER) AS CHAR)||' '||'Q'||' '||CAST(CAST(RIGHT('@{QUARTER}',1) AS INTEGER)-1 AS CHAR) END

The analysis gives me no results. And I have data in snapshots for many quarters so I dont know why it behaves like this....

Will aprreciate help

Alex

«13456

Answers

  • Joel
    Joel Rank 8 - Analytics Strategist

    If you have a well formed time dimension that has a corresponding logical dimensions with levels assigned, then you can easily achieve this by using the AGO time series function.

  • 3612030
    3612030 Rank 3 - Community Apprentice

    Ok I know, but there are many other details that prevents me from using this method. Mainly because I have to prompt for a Quarter and I have to see a data from that Quarter and historical data from quarter -1. And I dont know if function ago can support this.

    It has to be done through a presentation variable. Do you have any solution what can be done in that case?

  • Robert Angel
    Robert Angel Rank 8 - Analytics Strategist

    Amen to Joel's comment.

    But on your question - you seem to be missing a right parenthesis; -

    "Pipeline Snapshot Date"."Pipeline Snapshot Enterprise Quarter" IN (.......................  ) END  - there should be a bracket after that end statement.

    Also, in your example you show no space between Q and the number; - 2018 Q1; but in your syntax you concatenate a space in; -

    |'Q'||' '||'4'

  • 3612030
    3612030 Rank 3 - Community Apprentice

    Im sorry Robert, right bracket exists, I just omitted it here accidentaly...

    Also all the values are like "2018 Q 1" so my spaces are correct, again I just mistyped it here

    Here is the proof that data are correct:

    cac.JPG

  • Joel
    Joel Rank 8 - Analytics Strategist

    I don't see why this is a problem. All you need to do is to pass the Quarter entered in the dashboard prompt into a presentation variable and then calculate the previous quarter using the AGO function .

  • Robert Angel
    Robert Angel Rank 8 - Analytics Strategist

    Okay, if you have confirmed that your function returns exactly the same as your Quarters then I would change your IN to an equal sign;  =

  • Robert Angel
    Robert Angel Rank 8 - Analytics Strategist

    Probably also worth checking that your 2017 Q 4 is exactly what you see, check the length, just in case there is something you cannot see there.

    You might find it easier to strip the text and spaces out of it, then you can just take it away without all that cast and case.

  • 3612030
    3612030 Rank 3 - Community Apprentice

    Robert - unfortunately this doesnt change anything...

    Joel - can you give me an example of ago function with a presentation variable? Just remember that prompted quarted is from one Subject Area and the quarter ago is from Historical Pipeline.

  • Robert Angel
    Robert Angel Rank 8 - Analytics Strategist

    Try changing your filter to SQL and; -

    cast(replace(replace("Pipeline Snapshot Date"."Pipeline Snapshot Enterprise Quarter","Q","")," ","") as integer) = (cast(replace(replace('@{QUARTER}',"Q2","")," ","") as integer) -1)

    Cold coded - may need minor syntax fixes...

  • 3612030
    3612030 Rank 3 - Community Apprentice

    One more photo of the issued SQL:

    1rt.JPG