Difficulty accessing data by using the function of Ago - the end of the previous month

Hey,.

Recently, I met a problem that I can't fix on my own.


I need to compare my portfolio to the current date / specified with the portfolio for intelligence and for the end of the previous month (the last day of the previous month).

It looks like this :

Capture.JPG

My fact table consists of the list of contracts of loan that is updated daily. The data for the new day are added to the table, which actually resemble a large sandwich of various portfolios.


To recover the data for the current/specified date and intelligence is not a problem. Current date - the date is read (can 10.08.2014), the day before - I use the Ago function (e.g., 09.08.2014).

The real problem is getting the data for the last day of the month previous (e.g. 31.07.2014), since I can't put a specific to the function of Ago offset (10 days in our example), as the number of days from the end of the previous month is constantly - changing is a daily report.


The best solution would be setting the offset function there is a dynamic value, which would change according to the user selects the date of the report. Can be based on the number of days in the month. BI strictly prohibits using anything that is not an integer in the offset value, so this isn't an option.


I tried a work around using formulas in columns, like: FILTER ('facts of agreements'. "" Outstanding "USING ("Posting Date". "" Id of the day ' = TIMESTAMPADD (SQL_TSI_DAY, TIMESTAMPADD (1), (SQL_TSI_DAY, 'Date of Report'.) "Number of the day in the month" *-(1) + 1, DATE ' @{report_date}'))). "

It did not work, since the data I receive are dated the last day of the previous month and date, which is applied to get the data for the current date filter / specified, it cuts.


Tried to create another time the hierarchy, with the ends of period (week, month, quarter, year) and use it as a level at the Ago. He does work in part, offset the end of 1 month, but I can't bind the data, I get to the date of the report, as the Ago function returns random dates.


I tried to search if people have had the same problems and it seems I'm the only one. I'm really desperate at this point, not even sure it's possible to get the result I need everything.

So, please advise!


Aurore

Finally got sorted! Hoorey!

Here's how it's done:

I created a presentation variable 'report_date' for the user to choose the date of the desired report. That this formula has added to the column:

FILTER ('facts of agreements'. "" Outstanding "USING ("facts of agreements". (("" Days late max "> 30))-there is (FILTER ('facts of agreements'. "" Outstanding "USING ("facts of agreements". ((("" Days late max "> 30)), TIMESTAMPDIFF (SQL_TSI_DAY, TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH (DATE ' @{report_date}') *-1, DATE ' @{report_date}" "), DATE ' @{report_date}'))

Basically, this formula is used to calculate the difference between the current amount of the portfolio and the amount of portfolio for the last day of the last month (or at the end of last month), where only loans with number of days late over 30 are included.

In the service there, I used a TIMESTAMPDIFF as a compensation formula to calculate the difference in days between the date of the report and the end of last month. Now no matter what date the user chooses it will give the correct difference in days.

Really easy, but it took me a little time to get there.

Hope this helps someone

Tags: Business Intelligence

Similar Questions

  • Inserting data by using the query

    Hello

    In a book, I read the Sub statement:

    Inserting data by using the query (DML)

    If the user wants to transfer data from a table to another table in the insert statement are used independently of data that can be processed or not processed form.

    Can someone clarify what is the significance of this (processed or unprocessed form).


    Thank you.

    Why don't you ask the author of the book.

    How can we know what the author means when you take a quote out of context and don't provide any reference so that we can see exactly what is shown to you.

    I can only imagine that they are referring to data that are queried directly, "like what", another table, or who was interrogated and manipulated before be inserted.

  • Display the previous month data based on the chosen date

    Hi all

    I need the report of this requirement:

    The user selects an "Invoice Date" with guests, then it should be able to view the data of the previous month until the date (i.e.; If he chooses on 6 July in the hour that I need to view the data of June 6). How can I achieve this?

    Thank you
    Jerome

    Hi timestampadd function used in your filter.

    At the command prompt have a variable presentation as invoice_date and your report using the filter as below,

    "The date of the invoice" > = timestampadd(sql_tsi_day,-30,'@{invoice_date}')
    and "Date of the invoice.<=>

    Published by: kart on July 6, 2010 11:24

  • Function to retrieve all the days of the previous month.

    Hello

    Yes, it's a monthly report, I received the task at hand.

    So, all I need is every day of the previous month (even if there is no data for that day)

    I was instructed to use the following code, but it does not return a value any:
    DECLARE
       CURSOR CUR_LAST_DAY IS
          SELECT TO_CHAR (LAST_DAY (ADD_MONTHS (SYSDATE, -1) ), 'DD')
            FROM DUAL;
     
       VVA_LAST_DAY   VARCHAR2 (2);
       --
       VNU_JOUR       NUMBER       := 0;
    BEGIN
       OPEN CUR_LAST_DAY;
     
       FETCH CUR_LAST_DAY
        INTO VVA_LAST_DAY;
     
       CLOSE CUR_LAST_DAY;
     
       WHILE VNU_JOUR <= TO_NUMBER (VVA_LAST_DAY) - 1
       LOOP
          VNU_JOUR := VNU_JOUR + 1;
       END LOOP;
    END;
    --CLOSE CUR_LAST_DAY
    --DEALLOCATE CUR_LAST_DAY
    -----
    On the other end, I developed this code:
    SELECT TO_CHAR(SYSDATE,'dd')
    FROM DUAL
    WHERE TO_CHAR(SYSDATE,'dd') >= to_char(to_date(to_char(ADD_MONTHS(SYSDATE, -1),'yyyy-mm')||'-01'),'yyyy-mm-dd')
    AND TO_CHAR(SYSDATE,'dd') < to_char(LAST_DAY(to_date(to_date(to_char(ADD_MONTHS(SYSDATE, -1),'yyyy-mm')||'-01'),'yyyy-mm-dd')));
    Which returns a null value. :(

    Concerning

    Hello
    You want to retrieve whole days of the month last query... So here's...

    SELECT
    TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY') COMP_DATE,
    TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'DD') ONLY_DD,
    TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'MM') ONLY_MM,
    TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'YY') ONLY_YY
    FROM DUAL
    CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(LAST_DAY(ADD_MONTHS(SYSDATE,-1)),'DD'))
    

    I'm not at the machine database so not tested.

    But one thing do not forget that this forum only for reports, it is a separate SQL and pl/sql instance.
    Function to retrieve all the days of the previous month.

    -Clément

    Published by: Graham on April 22, 2010 22:53
    Spelling error

  • Release date of variable text for the previous month?

    I'm automating a package of reports based on the data received on the following month, day 8. I need models to pull in the month statement , not the month I publish to the course. Is it possible to perform such a feat? See you soon.

    You simply define the content of a block of text with the variable.

    There are several ways to do so, but if you put something weird in the model as XXXXXXXX you can use a search/replace.

    var x = new Date();

    with (x)

    {

    setDate (1);

    setMonth (getMonth () - 1);

    }

    var months = new Array();

    months [0] = "Jan";

    months [1] = "Feb.";

    months [2] = "March";

    months [3] = "April";

    months [4] = "may";

    months [5] = "June";

    months [6] = "July";

    months [7] = "Aug.";

    months [8] = 'Seven.';

    months [9] = "October";

    months [10] = "Nov";

    months [11] = 'Dec.';

    var y = x.getFullYear ();

    var m = month [x.getMonth ()];

    var lastmonth = m + "" + y;

    myDocument var = app.activeDocument;

    Clear the find/change text preferences.

    app.findTextPreferences = NothingEnum.nothing;

    app.changeTextPreferences = NothingEnum.nothing;

    Set the search options.

    app.findChangeTextOptions.caseSensitive = false;

    app.findChangeTextOptions.includeFootnotes = false;

    app.findChangeTextOptions.includeHiddenLayers = false;

    app.findChangeTextOptions.includeLockedLayersForFind = false;

    app.findChangeTextOptions.includeLockedStoriesForFind = false;

    app.findChangeTextOptions.includeMasterPages = false;

    app.findChangeTextOptions.wholeWord = false;

    Search the document for the string "XXXXXXXX" and change it to "text".

    app.findTextPreferences.findWhat = "XXXXXXXX";

    app.changeTextPreferences.changeTo = lastmonth;

    myDocument.changeText ();

    Clear the find/change text preferences after the search.

    app.findTextPreferences = NothingEnum.nothing;

    app.changeTextPreferences = NothingEnum.nothing;

    That save you and run when you open the document.

    Read the Guide to the script is a good thing to do no matter if it works for you, this time.

    Don't forget to mark this as replied to what works for you.

  • Are we losing Image Credits if we do not use over the previous month?

    Last month we used only about 30% of our appropriations allocated for the month. I just noticed that those who disappeared when our new payment hit. Is - this service a service "use them or lose them?" If Yes... GRRRRRRRR. If this isn't the case, how do get back us our lost credits?

    Hi Matt,

    You use the images/month 750 plan in which images do not carry forward to the next month.

    It occurs only for the 10 images/month plan.

    Kind regards

    Gerard

  • Extract the first and the last Date of the previous month

    This seems to be a delicate but again it is perhaps easy for some of you people.

    Here is how I find the previous month

    Any ideas on how to get the first and last date of the previous month?

    Thanks in advance.

    Hello!

    SQL>
    SQL> select last_day(add_months(sysdate,-1)) from dual;
    
    LAST_DAY
    --------
    28.02.10
    
    SQL> select trunc(add_months(sysdate,-1),'MM') from dual
    
    TRUNC(AD
    --------
    01.02.10
    
    SQL> 
    

    T

  • How to get sales last day of the previous month

    HELO guys

    I have a question how do I get sales date last day of the previous month where my fact table is level. in fact I tried using Ago but it seems not working. for example, if I chose December 29, 2014 so if I used the function there are then the result will display data on November 29, 2014 (not the last day of November 2014).

    Please guys if you have any solution and I really advise thanks to you.

    Not exactly under what circumstances specific as you try to reach this goal, but suppose you have a few guest dashboard where you select a day and you have a report with a measure where you want to show the sales of the last day of the previous month based on the selected date in the dash prompt.

    If you change the formula of this measure to something like:

    FILTER (with the HELP of 'Sales' (DATE = TIMESTAMPADD (SQL_TSI_DAY-1, TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH(@{PV_DATE_SELECTED}) * (-1) + 1, @{PV_DATE_SELECTED}))))

  • How to get the last business day of the previous month?

    Hi all

    We need the user as below,

    If the user select 18 June 2015 ' quick dashboard as the input value, and then they want to see last month last day of work (business date: 29-may-2015) amount in report, if you have an idea please share with us.thanks

    Note:

    use under request we can able to get the last day of the previous month, we want to for the last business day of the last month, based on the date of entry of the user?

    TIMESTAMPADD (SQL_TSI_DAY,-(1), TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH ("DIM_TIME". ("" DataDate ") *-(1) + 1,"DIM_TIME ". (("" DataDate "))

    Thank you

    Deva

    Try this,

    case when Dayofweek (timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15')) = 1 then timestampadd (sql_tsi_day, (Dayofmonth(Date '2015-06-15') *-1)-2, Date '' 2015-06-15) when Dayofweek (timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15')) = 7 then timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1-1, Date '' 2015-06-15) another timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15') end

    As Ftsiot said in this post, it will work only to exclude the sat and Sun. Another one if you want to exclude regional holiday, you may need a calendar in DB table.

    Thank you

    AJ

  • retrieve December as the previous month in 2013

    All,

    I used this code to retrieve the previous and upcoming months last year that worked very well...
    If the date was for example September 7, then a list of the previous months must be shown, and a list of the next months including the current month.
       select  to_char(to_date(level,'mm'),'FMMonth') month
       from  dual
       connect by level < to_number(to_char(sysdate,'mm'))
    
     
    MONTH
    ---------
    January
    February
    March
    April
    May
    June
    July
    August
     
     select  to_char(add_months(sysdate,level - 1),'FMMonth') month
      from  dual
     connect by to_number(to_char(add_months(sysdate,level - 1),'mm')) != 1
     
     
    MONTH
    ---------
    September
    October
    November
    December
    Now we are in January 2013.
    When I run the code for the previous months, there is no line. It is right that there is no previous month again in 2013.

    I would like to extend the code to display December 2012 as the previous month at the beginning of the year.
    How can I achieve this?

    Thank you
    Diana

    Hello

    Try this:

    select
      to_char(trunc(add_months(sysdate, -level) ,'month'),'FMMonth-yyyy') previous_months
    
    from
      dual
    
    connect by
      level <= case when to_number(to_char(sysdate,'mm')) = 1 then 12
                    else to_number(to_char(sysdate,'mm'))-1 end
    
    order by
      add_months(sysdate, - level)
    

    If wew replace sysdate with date ' 2013-01-08' then it results in:

    select
      to_char(trunc(add_months(date '2013-01-08', -level) ,'month'),'FMMonth-yyyy') previous_months
    
    from
      dual
    
    connect by
      level <= case when to_number(to_char(date '2013-01-08','mm')) = 1 then 12
                    else to_number(to_char(date '2013-01-08','mm'))-1 end
    
    order by
      add_months(date '2013-01-08', - level)
    ;
    PREVIOUS_MONTHS
    ---------------
    January-2012
    February-2012
    March-2012
    April-2012
    May-2012
    June-2012
    July-2012
    August-2012
    September-2012
    October-2012
    November-2012
    December-2012   
    
     12 rows selected 
    

    If we replace sysdate with date ' 2013 - 02 - 08, then we get:

    select
      to_char(trunc(add_months(date '2013-02-08', -level) ,'month'),'FMMonth-yyyy') previous_months
    
    from
      dual
    
    connect by
      level <= case when to_number(to_char(date '2013-02-08','mm')) = 1 then 12
                    else to_number(to_char(date '2013-02-08','mm'))-1 end
    
    order by
      add_months(date '2013-02-08', - level)
    ;
    
    PREVIOUS_MONTHS
    ---------------
    January-2013    
    

    Same thing for 2013 - 05-08 "

    select
      to_char(trunc(add_months(date '2013-05-08', -level) ,'month'),'FMMonth-yyyy') previous_months
    
    from
      dual
    
    connect by
      level <= case when to_number(to_char(date '2013-05-08','mm')) = 1 then 12
                    else to_number(to_char(date '2013-05-08','mm'))-1 end
    
    order by
      add_months(date '2013-05-08', - level)
    ;
    
    PREVIOUS_MONTHS
    ---------------
    January-2013
    February-2013
    March-2013
    April-2013      
    

    Kind regards

    Peter

  • DAY MONTH FOR THE previous month

    Hello

    I invited where I have dates like below

    31/03/2012
    30/04/2012
    When I clcik 30/04/2012, I need previous months the other day, then the result should be 31

    When I give it as this TIMESTAMPADD (SQL_TSI_DAY,-30, DATE ' @{pvdate} "")... I get previous full day 31/03/2012
    When I give it as this DAYOFMONTH (DATE ' @{pvdate} "")... I get months current 30 day

    How to get the previous month of day?

    If you use guests then SQL result or in the SQL report to filter or fx on column

  • Cannot restore to a restore point from the previous month.

    original title: my system restore won't let me restore to the previous month, the radio button works, but the habit of restoration

    my windows XP THAT behaves strangely and I tried to use the system restore which has worked well in the past, but now he's depressed the option button but nothing happens

    Roy

    Hello

    1. are you able to restore the computer to other points of restoration?

    2. you receive an error message when you try to perform the system restore?

    If you are not able to restore the computer to any pint of previous restoration then you can check the steps in the link below to fix the problem.

    Steps of troubleshooting for problems when you try to use the System Restore tool in Windows XP

    http://support.Microsoft.com/kb/302796

  • Download of the previous months

    I signed up for Stock a few months ago. Unfortunately, I had a few personal problems because of which I had to take a break. I came back to the content of the license and realized that my previous allowances do not. I was under the impression that 10 permit licenses for June and July meant that, in the month of August, I would have 30 license. However, I don't see 10.

    Is it possible to download the licenses of the previous month I have not used?

    As long as your subscription has been paid, you should have these credits. Otherwise, open a session completely exhausted, close your browser, clear the cache of your browser and try again.

  • Compare the amount of the previous month based on the account number

    Hi team,

    In my table of the source, amount aggregated by month for a given account there
    ACCOUNT_NUMBER          YEAR          MONTH          AMOUNT
    ---------------          -------          ------          -----------
    123456789          2012          01          450.00
    123456789          2012          02          -234.00
    123456789          2012          03          0.00
    123456789          2012          04          890.00
    123456789          2012          05          78.00
    123456789          2012          06          44444.00
    123456789          2012          07          450.00
    123456789          2012          08          450.00
    123456789          2012          09          450.00
    123456789          2012          10          120.67
    123456789          2012          11          176.88
    123456789          2012          12          450.00
    123456789          2013          01          340.00
    Now, I need to add a column more in this area, with logic below. There will be more than 1000 accounts available. For each account I need to achieve this.

    CASE WHEN MONTH_AMOUNT = 0 THE CASE OTHERWISE 1-0 WHEN PREVIOUS_MONTH_AMOUNT = 0 THEN 0 1 OTHER)

    On this basis, the objective should be
    ACCOUNT_NUMBER          YEAR          MONTH          AMOUNT          FLAG
    ---------------          -------          ------          -----------     -------------
    123456789          2012          01          450.00          1
    123456789          2012          02          -234.00          1
    123456789          2012          03          0.00          -1
    123456789          2012          04          890.00          1
    123456789          2012          05          78.00          1
    123456789          2012          06          44444.00     1     
    123456789          2012          07          450.00          1
    123456789          2012          08          450.00          1
    123456789          2012          09          450.00          1
    123456789          2012          10          0.00          1
    123456789          2012          11          0.00          0
    123456789          2012          12          450.00          1
    123456789          2013          01          340.00          1
    can someone help me how to compare the value of the previous month. All columns have the data varchar, except for the quantity type.

    Hello

    I have not tried. But this desire.

    SELECT
    ACCOUNT_NUMBER,
    YEAR,
    MONTH,
    AMOUNT,
    CASE WHEN AMOUNT = 0 THE 0 ELSE 1 - CASE WHEN LAG(AMOUNT, 1, 0) OVER (PARTITION BY ACCOUNT_NUMBER ORDER BY YEAR, MONTH) = 0 THEN 0 ELSE 1) AS FLAG
    FROM SOURCE_TABLE;
    

    See you soon
    Didier

    Published by: Didier vishwakarma on 6 March 2013 12:36

  • extract the previous month of sysdate

    The following SQL statement returns zero output.
    SELECT DISTINCT EXTRACT(MONTH FROM SYSDATE) - 1 PRVMNTH FROM DUAL
    I want to request to return to the previous month on any date given (sysdate).

    Help, please.

    Yogesh
    SQL> select extract (month from add_months (sysdate, -1))
      2    from dual
      3  /
    
    EXTRACT(MONTHFROMADD_MONTHS(SYSDATE,-1))
    ----------------------------------------
                                          12
    

    Why the separate?

Maybe you are looking for

  • Satellite L40 - 14Y Bios Update with HARD drive empty

    I need to update the Bios of my Satellite L40 - 14Y / PSL48E-01F01UGR of Version 1.60 to 5.50 (for Windows XP). The HARD drive is _ * authorized/empty * _. My problem: the 'solution' as given [Http://eu.computers.toshiba-europe.com/innovation/faq.jsp

  • Reset Game hearts

    How long should I stay 'inactive' until my heart of note and the number of games played resets

  • Why my windows xp stops leaving a message in energy saving mode

    If I run a virus scan or malware check the computer stops and it says power saving mode.   How can I fix it?

  • Empty folder AppData

    Hi all So here's my problem. I am away at College and I was home for the summer and don't end up using my computer for like 2 months right because I've been so busy. I recently had to go back and do an assignment so I turned on my computer and there

  • Apple - should apply to master VM updates? Or ok to apply to Linked Clone?

    Title says it all. Master 10.10.3 VM. Linked clone used for day to day stuff.Today released an update to iTunes. Make the update to the Master VM? That would make the most sense for me.Or should we not alter the master and apply the update to iTunes