Thank you for supporting the Cloud Customer Connect Community in 2024. It's a gift to work with you!

Look back
You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register
Get Started with Redwood for Oracle Cloud HCM   Begin Now
To ensure that questions get required attention from community members and are NOT left unanswered, it’s important for the author to indicate (by selecting “Yes” or “No” when prompted) whether the question was answered. (newly added) Please note that it is also important to respond to EACH comment your question receives. Your Yes or No response ensures an accurate status for your question.

For more information, please refer to this announcement explaining best practices for getting answers to questions.

how to get previous month first_date & last_date in bi publisher?

Naresh KnK
Naresh KnK Green Ribbon
edited Mar 9, 2020 5:05PM in Reporting and Analytics for HCM 19 comments
Tagged:

Answers

  • User_BO6Q8
    User_BO6Q8 Silver Medal
    edited Mar 9, 2020 5:17PM

    try this:

    SELECT

    Last_Day(ADD_MONTHS(SYSDATE,-2))+1 First_day,
    Last_Day(ADD_MONTHS(SYSDATE,-1)) Last_day

    FROM DUAL

  • Janardhana K
    Janardhana K Silver Crown
    edited Mar 10, 2020 12:50PM

    You will try and see what are all the below options possible for defaulting date parameters for BI Report.

    Expression

    Description

    Date Format String

    {$SYSDATE()$}

    Current Date / System Date

    MM-dd-yyyy

    {$SYSDATE()+1$}

    Day next to System date

    MM-dd-yyyy

    {$SYSDATE()-7$}

    7 days prior to System date

    MM-dd-yyyy

    {$FIRST_DAY_OF_MONTH()$}

    First day of Current Month

    MM-dd-yyyy

    {$LAST_DAY_OF_MONTH()$}

    Last day of Current Month

    MM-dd-yyyy

    {$FIRST_DAY_OF_YEAR)$}

    First day of Current Year

    MM-dd-yyyy

    {$LAST_DAY_OF_YEAR)$}

    Last day of Current Year

    MM-dd-yyyy

    {$SYSDATE()$}

    Current Period

    MM

    {$FIRST_DAY_OF_MONTH()-1$}

    Previous Period

    MM

    {$FIRST_DAY_OF_YEAR)$}

    Current Year

    yyyy

    {$FIRST_DAY_OF_YEAR)-1$}

    Previous Year

    yyyy

  • Naresh KnK
    Naresh KnK Green Ribbon
    edited Mar 10, 2020 1:13PM

    Hi Janardhan,

    When i select this function {$FIRST_DAY_OF_MONTH()-1$},It is picking previous month last date. 

    How to get first day of previous month?

    Thanks,

    Naresh

  • Janardhana K
    Janardhana K Silver Crown
    edited Mar 10, 2020 1:45PM

    I assume the First Day of Previous Month functions are not supported in BI Date parameters.

    Please fallow the below workaround methods;

    1. First day of the previous month:

    The only option you have is:
    Create an LOV:
    SELECT ADD_MONTHS((LAST_DAY(SYSDATE)+1),-2) FROM DUAL
    and a Menu parameter based on the above LOV.

    The restriction you will have are:
    It returns data in online mode and only if it is setup as CSV format by default
    If you try to schedule the report with other format than CSV, it will fail with “Invalid parameters requested”
    You will not have the option to change the parameter value from default First day of last month to a user selected value from the calendar.

    Regarding the CSV format:
    CSV is a data format.
    Scheduling has to use the exact same parameter values as online.
    The value is static, will be the same for each run, unlike the {$SYSDATE()$} dynamic values.
    This means the only way you can make this work is to create individual scheduled jobs for each month.

     

    2. Last day of the previous month:

    {$FIRST_DAY_OF_MONTH()-1$}

  • Hi all - are there a similar set of functions for OTBI? I am trying to convert a date to the last day of the month it falls in?

  • Yes, this is possible in OTBI, look for TIMESTAMPADD function.

  • Thank you - we didn't realize we should use that function for all of the dates in OTBI and I really appreciate the help and quick replies!

  • hi All,


    I need the first day of the last month in the OBTI parameter, can anyone help me please?

  • Hi @Sumedh Kumar-Oracle,

    I have used the below which I found online:

    First day of last month

    SELECT TIMESTAMPADD(SQL_TSI_MONTH, -1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))

    FROM "Workforce Management - Historical Processed Time Cards Real Time"


    Last day of last month

    SELECT TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) 

    FROM "Workforce Management - Historical Processed Time Cards Real Time"

    Please substitute the subject area name to the one you are using. When I added the above as prompts for the between dates and ran it today (2nd April) I can see the following as expected:


  • Is there any way to get the first day of the previous quarter?

  • Hi @MaartenDIF,

    The below should give you first day of previous quarter.

    TIMESTAMPADD( SQL_TSI_QUARTER , -1, TIMESTAMPADD( SQL_TSI_DAY ,EXTRACT( DAY_OF_QUARTER FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE))

    Thanks

    Mark

  • @Mark Stoker It is giving me an error (Invalid date format). I think this is OTBI format, not BIP.

    I've tried a lot of different variations and I cannot find any working code for the 'EXTRACT(DAY_OF_QUARTER…' part. Also, BIP only accepts SYSDATE() and not CURRENT_DATE. TRUNC(SYSDATE(), 'Q') also not working.. I have no idea how to resolve this.

  • Hi @MaartenDIF,

    Can you see if the below works?

    Select ADD_MONTHS(TRUNC(SYSDATE, 'Q'), -3) AS First from Dual

    Thanks

    Mark

  • Satyam Roy
    Satyam Roy Bronze Trophy
    edited Jul 12, 2024 5:38AM

    Thanks for the information all.

  • @Mark Stoker

    This works well when putting it directly in the data model. However, the BIP parameters are a different beast:

    So far I've only got specific system parameters subtraction/addition to work, so no functions (like add_months).
    There's some other data parameters that work aside from the SYSDATE. @Janardhana K linked them earlier in this thread.

    If there's no other workaround I will need to duplicate the DataModel and hard-code this parameter for the schedule. I'd rather not, because it will increase maintenance whenever there's changes to this report (and that happens quite often).

  • Hi, MaartenDIF

    Have you found better way?

    We are facing similar issues right now as

    I need to give dynamic value as first date of last month since user only wants to see actual shipment out last month on report run date.

    And that report will be scheduled to run once per month but even that I do not want to schedule it 12 times either.

  • I managed to default the date parameter in the Data Model to the first day of month for 6 months back like this:

    • the date format string is yyyy-MM
    • the default expression is either {$sysdate()-180$} or {$first_day_of_month()-180$} (they both work)

    Hope this helps.