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

Tags: Database

Similar Questions

  • How to get the account number so that repated id in a query result

    Hello
    I have a problem to add a registered number and the number of ID attributes, repeated in the result set of a query.
    the query is

    SQL > Select Distinct SC. Claimid.
    2 SC. LASTMODIFIED QUERYDATE,
    3 SC. STATUSID,
    4 tt2. Remarks1
    status_claims sc 5
    6 Left Join (Select LISTAGG (REMARKS, ',') within the Group (order IN SC1. CLAIMID) Remarks1,.
    7 SC1. CLAIMID
    CLAIM_REMARKS SC1 8
    9. WHERE SC1. REMARK_ID IN (1, 2, 3, 7, 8, 9)
    10 AND SC1. STATUSID (51)
    11 GROUP SC1. TT2 CLAIMID)
    12 on tt2. CLAIMID = SC. CLAIMID
    where the 13 sc.statusid (11)
    14 and SC.claimid in (19970, 19980, 20032)
    15 sc.claimid, sc.lastmodified;

    and the output is

    claimID QUERYDATE STATUSID
    -------- -------------------
    19970 13 MAY 11 10.11.39.643000 11 H
    19970 13 JUNE 11 12.43.25.029000 11 H
    19980 17 JUNE 11 01.00.54.742000 11 H
    19980 17 JUNE 11 01.00.54.742000 11 H
    20032 23 MAY 11 11.40.12.804000 11 H
    20032 22 JUNE 11 12.22.16.642000 11 H
    20032 JULY 11, 11 02.43.08.113000 11 H

    The output above should be like this

    claimID County QUERYDATE STATUSID
    -------- ------------------- -------------------- --------------
    19970 13 MAY 11 10.11.39.643000 11 1 AM
    19970 13 JUNE 11 12.43.25.029000 11 2 H
    19980 17 JUNE 11 01.00.54.742000 1 11 PM
    19980 17 JUNE 11 01.00.54.742000 11 2 H
    20032 23 MAY 11 11.40.12.804000 11 1 AM
    20032 22 JUNE 11 12.22.16.642000 11 2 H
    20032 JULY 11, 11 02.43.08.113000 3 11 PM


    If claimids increase the number should also increase based on the claimids

    Thanks in advance.,
    Kind regards
    Vikram.

    Hello

    Try like this

    Select Distinct SC.Claimid,
     SC.LASTMODIFIED QUERYDATE,
     SC.STATUSID,
     tt2.Remarks1
     row_number() over(partition by sc.claimid order by sc.lastmodified nulls last) slno
     from status_claims sc
     Left Join (Select LISTAGG(REMARKS, ', ') within Group(order BY SC1.CLAIMID) Remarks1,
     SC1.CLAIMID
     FROM CLAIM_REMARKS SC1
     WHERE SC1.REMARK_ID IN (1, 2, 3, 7, 8, 9)
     AND SC1.STATUSID IN (51)
     GROUP BY SC1.CLAIMID) tt2
     on tt2.CLAIMID = SC.CLAIMID
     where sc.statusid in (11 )
     and SC.claimid in (19970, 19980, 20032)
     order by sc.claimid, slno;
    

    SA

  • 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}))))

  • Comparing the first four digits

    Hello


    I need to compare two different tables say account numbers a and b



    I need to select the first four digits of the account number of 'b' and which correspond with the first four digits 'a'



    for example in b if I have the account number from - 1234

    I need to select all the account numbers from a starting with 1234 - like 1234567, 1234789etc.,.


    Please help me

    Hello

    Account numbers are really numbers and not the chains?
    If the two numbers have different lengths (e.g. 1234567 and 1234) do you always want to compare the first four digits?

    Assuming that the answers to both is "Yes":

    ...
    WHERE   SUBSTR (TO_CHAR (a.account_number), 1, 4) =
            SUBSTR (TO_CHAR (b.account_number), 1, 4)
    

    If the account_numbers are really chains, omit TO_CHAR.

  • Higher than the usual number of download errors

    Hello

    I was just curious if anyone here knew nothing of a level higher than the usual number of download errors I hear on clients.

    The anaylytics seems to backup the fact that several of our downloads fail outside the previous months (based on the new issue that comes out).

    Is there some sort of infrastructure maintenance going on right now?

    Thanks for any idea that you might be able to provide!

    Gold support would be the correct place. I don't know who you might meet instead of. I know that some members of staff watching these forums, but this isn't the resource, so that they are intended to be used.

  • Bank account number in the field 'Pay to the bank account number' must be regarded as * Bill in summary view

    Find the invoice - > Bill Workbench, there is a tab named as deadlines. In this tab, there is a field called mission to bank account, so is the account number must be regarded as * on a mission to the bank account.

    Do not know how to do.

    Thank you

    Hello

    Use the following form customization:

    (As it is for 11i rel, some area/block names may differ)

    Condition

    Trigger event-> a TIME NEW BLOCK INSTANCE

    Trigger object-> PAYMENT_SCHEDULE

    Action

    Type a-> property

    Object-> point type

    Target-> PAYMENT_SCHEDULE object. BANK_ACCOUNT_NUM

    Name of the property-> value

    Value-> *.

    Save your work, close all forms and test them.

    Octavio

  • Why doesn't the serial number on the box of 14 elements for installation?

    I bought 14 items in a box with a serial number of 18 digits, a number nine PN, five code a lot of numbers and a bar code with 12 numbers beneath him. The two discs in the box of each has a code on a sticker eight-digit.

    When I try to do an installation, after accepting the license, it gives me six boxes and asks me to put the serial number in these areas.  None of the numbers provided by Adobe seem to fit or work.  I tried the cat, and for 30 minutes, the agent told me to 'take a screenshot of the box', so he could consider it.  But he was unable to tell me how I had to get a screenshot of something not in my computer.  He will have to do a print screen of the computer.  He doesn't seem to understand this.   I finally took a picture with my iPhone, it loads on my desktop and I tried to "add" it to the cat.  I got a message saying that he had been transferred to Adobe.  But he said that he does not understand.  He also insisted that I must put the account number of chat on the screenshot, yet once he could not explain how to do this.  You click Add, boring down into the file, and then click ok.  No place to type in numbers.  Finally, I gave up.

    Should not be this hard load a program I bought, which came on a drive.  Or should it be difficult to reach the seller to find out what the problem is.  But I can't find any support phone for items.  Does anyone have any suggestions?  Or I just go back to the store?

    MacBook Pro i7, OS X El Capitan 1.2 TB of free space on hard drive

    Serial numbers are 24 digits (no letters) in 6 groups of four, is usually found inside the box on the cover of disc or another container internal.  They are not displayed off the beaten path because anyone could use them.

    Find the serial number of your Adobe product quickly

  • FDM as Script for the account mapping

    I use the following script as a 'Like' card for the account. The import file has account in this format: 123456-Description. I would like to delete everything after the "-" and set the result to just the account number; However, I get an error saying card conditional Script error: expected "End" to line (4)

    sParse ="-"
    IPOS = InStr (varValues (13), sParse)
    If iPos = 0 Then Result = varValues (13)
    Else Result = Left (varValues (13), iPos-1)
    End If

    Someone knows how to fix the error? I tried to move the End If up to line 4, but that did not help.

    Thank you.

    Terri T.

    The RESULT setting should be on its own line of the if statement as follows:

    sParse="-"
    ipos=InStr(varValues(13),sParse)
    If iPos=0 Then
         RESULT=varValues(13)
    Else
         RESULT=Left(varValues(13),iPos-1)
    End If
    
  • 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

  • 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

  • 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

  • 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

  • List date values in the current month and previous month next month

    Hello. I am looking for a way to query a list of each value date in the current month, previous month and next month.

    1 DECEMBER 15

    ...

    ...

    31 DECEMBER 15

    1ST JANUARY 16

    ...

    ...

    30 JANUARY 16

    1 FEBRUARY 16

    ...

    ...

    28 FEBRUARY 16

    Any help would be greatly popular!

    with the data (start_date and end_date) as)

    Select Add_months (trunc (sysdate, 'month'),-1),

    Add_months (trunc (sysdate, 'month'), 2)

    of the double

    )

    Select the level - 1 the_date + start_date

    from the data

    connect by level<= end_date="" -="">

  • 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 months in the calculation

    Hi guys,.

    I have a question about calculations in Essbase (calcscript).

    I want to know if a month (for example Jan) is less than (<) the other month (e.g., Feb).

    The first month is in a variable (& BasePeriod), the second month is @currmbr (periods).

    A comparison between these is fine for the following operators: <>, ==.

    But I need to know if the first is 'small' (earlier in my size) than the other.

    My rules are in a time dimension.

    And are built like:

    Year

    1ST QUARTER

    Jan

    Feb

    Mar

    etc.

    I hope you guys can help.

    Right, but you are not asked to compare the two members of dimension period arbitrary; only & BasePeriod and @CURRMBR ("Periods"):

    «The first month is in a variable (& BasePeriod) second month is @currmbr (periods).»

    But I need to know if the first is 'small' (earlier in my size) than the other. »

    @ISMBR("Jan":&BasePeriod) returns TRUE when @CURRMBR (Periods) is earlier or equal to & BasePeriod

    @ISMBR("Jan":&BasePeriod) AND NOT @ISMBR(&BasePeriod) returns TRUE if @CURRMBR ("Periods") is prior to & BasePeriod

    To compare the other way around you can reduce to zero the expression.

    @ISMBR("Jan":&BasePeriod) NO returns TRUE when & BasePeriod is earlier than @CURRMBR ("Periods")

    NO @ISMBR("Jan":&BasePeriod) OR @ISMBR(&BasePeriod) returns TRUE & BasePeriod is earlier or equal to @CURRMBR ("Periods)

    Is it not what you ask?

Maybe you are looking for