Nearest value

i have a target of developing aging report of vendor payments
but payment is not marking billwise
now if party credit amount is 50000
then i have to go to the nearest record to 50000
for e.g there are eleven bills of party
last one amount is 15000
seocnd last 16000
third last 17000
and then 40000
the need a query that will fetch records upto 17000 as the sum of last three payments equals to (48000) that is nearest to 50000 of total credit

I'm not sure what you're asking there?
Do you mean what happens if the latest and latest but one are equally close to the specified amount (one above, one below)?
I've gone with including the amount above the cutoff limit (figuring that if these are bills that the company demands the debtor must pay, then the company wants to get as much money as possible).
changing
where   abs_diff <= nvl(abs_diff_prev, abs_diff)
to
where   abs_diff < nvl(abs_diff_prev, abs_diff+1)works if you only want to include the row less than the set limit in that specific case.
Eg:
with my_tab as (select 1 cust_id, 40000 amount, trunc(sysdate -19) bill_date from dual union all
                select 1 cust_id, 17000 amount, trunc(sysdate -16) bill_date from dual union all
                select 1 cust_id, 16000 amount, trunc(sysdate -5) bill_date from dual union all
                select 1 cust_id, 15000 amount, trunc(sysdate -1) bill_date from dual union all
                select 1 cust_id, 22000 amount, trunc(sysdate -22) bill_date from dual union all
                select 2 cust_id, 20000 amount, trunc(sysdate -2) bill_date from dual union all
                select 2 cust_id, 29000 amount, trunc(sysdate -1) bill_date from dual union all
                select 2 cust_id, 2000 amount, trunc(sysdate -6) bill_date from dual union all
                select 2 cust_id, 14000 amount, trunc(sysdate -10) bill_date from dual union all
                select 3 cust_id, 20000 amount, trunc(sysdate -2) bill_date from dual union all
                select 3 cust_id, 31000 amount, trunc(sysdate -8) bill_date from dual union all
                select 3 cust_id, 12000 amount, trunc(sysdate -10) bill_date from dual union all
                select 4 cust_id, 66000 amount, trunc(sysdate -2) bill_date from dual)
-- end of creating mock-up of my_tab table. Now, onto the query:
select cust_id, amount, bill_date
from   (select cust_id, amount, bill_date, abs_diff, lag(abs_diff) over (partition by cust_id
                                                                          order by bill_date desc) abs_diff_prev
        from   (select cust_id,
                       amount,
                       bill_date,
                       abs(50000-sum(amount) over (partition by cust_id
                                         order by bill_date desc)) abs_diff
                from   my_tab))
where   abs_diff <= nvl(abs_diff_prev, abs_diff+1)
order by cust_id, bill_date desc
CUST_ID     AMOUNT     BILL_DATE
1     15000     05/11/2008
1     16000     01/11/2008
1     17000     21/10/2008
2     29000     05/11/2008
2     20000     04/11/2008
2     2000     31/10/2008
3     20000     04/11/2008
3     31000     29/10/2008
4     66000     04/11/2008
with my_tab as (select 1 cust_id, 40000 amount, trunc(sysdate -19) bill_date from dual union all
                select 1 cust_id, 17000 amount, trunc(sysdate -16) bill_date from dual union all
                select 1 cust_id, 16000 amount, trunc(sysdate -5) bill_date from dual union all
                select 1 cust_id, 15000 amount, trunc(sysdate -1) bill_date from dual union all
                select 1 cust_id, 22000 amount, trunc(sysdate -22) bill_date from dual union all
                select 2 cust_id, 20000 amount, trunc(sysdate -2) bill_date from dual union all
                select 2 cust_id, 29000 amount, trunc(sysdate -1) bill_date from dual union all
                select 2 cust_id, 2000 amount, trunc(sysdate -6) bill_date from dual union all
                select 2 cust_id, 14000 amount, trunc(sysdate -10) bill_date from dual union all
                select 3 cust_id, 20000 amount, trunc(sysdate -2) bill_date from dual union all
                select 3 cust_id, 31000 amount, trunc(sysdate -8) bill_date from dual union all
                select 3 cust_id, 12000 amount, trunc(sysdate -10) bill_date from dual union all
                select 4 cust_id, 66000 amount, trunc(sysdate -2) bill_date from dual)
-- end of creating mock-up of my_tab table. Now, onto the query:
select cust_id, amount, bill_date
from   (select cust_id, amount, bill_date, abs_diff, lag(abs_diff) over (partition by cust_id
                                                                          order by bill_date desc) abs_diff_prev
        from   (select cust_id,
                       amount,
                       bill_date,
                       abs(50000-sum(amount) over (partition by cust_id
                                         order by bill_date desc)) abs_diff
                from   my_tab))
where   abs_diff < nvl(abs_diff_prev, abs_diff+1)
order by cust_id, bill_date desc
CUST_ID     AMOUNT     BILL_DATE
1     15000     05/11/2008
1     16000     01/11/2008
1     17000     21/10/2008
2     29000     05/11/2008
2     20000     04/11/2008
3     20000     04/11/2008
3     31000     29/10/2008
4     66000     04/11/2008Note the difference between the two results for cust_id = 2.

Similar Messages

  • Rounding off to nearest value with formatNumber

    Can I use the formatNumber tag to round my numeric value to the nearest value?
    Like if it's 15.7 I would like to display 16
    And if it's 15.2, I would like to display 15
    I could successfully truncate by giving a patteren but Im not sure if I can round it off.
    Regards,
    Leena

    Yes you can - the following works on JSTL 1.1 / Tomcat 5.5 :
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <html>
    <head><title></title></head>
    <body>
    Test Auto Rounding of 16.8 :
    <fmt:formatNumber value="16.88" pattern="##"/>
    <br/><br/>
    Test Auto Rounding of 16.2 :
    <fmt:formatNumber value="16.22" pattern="##"/>
    </body>
    </html>Message was edited by:
    appy77

  • SQL for rounding to the nearest value

    Hi All,
    My Oracle DB version is 10g Release2 and also 11gR1
    I have data like below, I need to write a SQL for the below requirement.
    ID   RANGE_LOW                RANGE_HIGH
    1      50                    55             
    2      55                    60
    3      60                    63 
    4      63                    77 
    5      77                    84   The requirement is like I need to check a value between the above range low and high then round it to the nearest value.
    Say, for example if I have 68 then the value is rounded to 63 else if 74 then 77 else if its in the middle of two values (70) then rounded to the highest value, here its 77.
    Please advice.

    Ashu_Neo wrote:
    hi Purvesh,
    I think , you didn't check it properly with requirement of posting. Your query needs to be changed a bit. Please verify againYes, I probably missed or overlooked the last line.
    Here is the updated solution then:
    with data as
      select 1 id, 50 low, 55 high from dual union all
      select 2, 55, 60 from dual union all
      select 3, 60, 63 from dual union all
      select 4, 63, 77 from dual union all
      select 5, 77, 84 from dual 
    chk_val as
      select &val val from dual
    select id, low, high,
           val input_value,
           case
            when val < (low + high)/2
              then low
            else
              high
           end round_value
      from data, chk_val
    where val between low and high;
    ID                     LOW                    HIGH                   INPUT_VALUE            ROUND_VALUE           
    4                      63                     77                     70                     77

  • Finding the nearest value.

    Hi Gurus,
    I have an internal table with values country code and current price and using a selection screen i get a price, now i need to pick a value from the table which is nearest to the one in the screen. How do i achieve this logic? All help regarding this is very much appreciated.
    Thanks,

    give 10 as input and execute this program
    parameters:valin type p.
    data:begin of itab occurs 0,
          val type p decimals 2,
         end of itab.
    itab-val = '10.13'.
    append itab.
    itab-val = '14.13'.
    append itab.
    itab-val = '9.13'.
    append itab.
    itab-val = '4.13'.
    append itab.
    itab-val = '22.13'.
    append itab.
    sort itab descending.
    loop at itab where val <= valin.
    write itab-val.
    exit.
    endloop.

  • UIDatePicker doesn't snap or animate to the nearest value

    I use a UIDatePicker for a users Date Input, my Date Picker is inside a UIView, and on all OS Revisions and Devices (that I have tested) except "iPad 1" iOS 5.x -- everything works great.  On iPad 1 with iOS 5.x when you scroll a wheel it stops inbetween months/days/years and does not animate to the nearest date.  It also therefor does not set the date (it appears the date is only set when the exact date is reached [or close to it] and not if it stops inbetween.
    I have read that CCDirector causes issues with the UIDatePicker on iPad 1 iOS 5.x, but I do not use cocos2d, however, it points out that there may be an issue somewhere where I am doing something similar.
    Any thoughts?
    --Dave

    I have this problem too (ios 5.1.1, ipad 1). You find solution?

  • Rounding off value problem in sales order

    Hi All,
    This is related to a rounding off value problem in sales order.
    The problem is described by an example which is as follows -
    Selling Price of Material A = Rs. 176.76
    Excise charged = Rs. 21.80
    Total Price = Rs.176.76 + Rs.21.80 = Rs. 198.56
    On this total Trade Discount (ZDTD) having access sequence,is calculated  at the rate of 4% = Rs. 7.94
    But the condition base value after the discount is showing Rs.198.60 instead of Rs.198.56
    I want the system to reflect the value as Rs.198.56 intact and it should not round up to the nearest value i.e. Rs. 198.60
    Why is this happening? Is it possible to reflect the exact value? If yes what is needed to be done?
    The commercial round off is activated for the DIFF Condition Type.
    Looking forward to some valuable suggestions.
    Thanks & Regards
    Priyanka Mitra

    Hi Ramesh,
    Thanks for your suggestion but the problem has been solved by me.
    Regards
    Priyanka Mitra

  • FR 9.3.1 - Show point values doesn't work properly

    Greetings,
    I'm experiencing a strange trouble with the show point values function in charts like Bar, Line or Combo Chart types.
    The values diplayed are rounded to the nearest value, even if the grid show decimal values.
    I didn't find any solution to this, maybe anyone knows how to fix it?
    Thank you very much for your support.

    There is a work around, note that this is not supported/approved by Oracle as it involves actually changing the report xml. So at your own risk:
    # You need to export the FR reports;
    # Then open in a text editor;
    # Search for the current format (it should be '%,d', with the single quotes);
    # Replace with the format you want, for example to get one decimal place with 000's separator '%,8.1f'
    Formatting types/descriptions:
    bq. %g example 1234.456 \\ %f example 1234.46 \\ %,f example 1,234.46 \\ %d                example 1234 \\ %,d                example 1,234 \\ %8.1f                example 1234.5 \\ %08.1f           example 001234.5 \\ cost=$%,.1fM     example Cost=$1,234.5M
    To add this for the second Y axis, you actually need to do more work:
    # Within the exported .DES file, Search for &lt;CHARTOBJECT
    # Then search for OBJECT_WIDTH (There are OBJECT_WIDTH parameters for objects other than charts, which is why we start at the Chart section first.)
    # 1.Add the following parameters after OBJECT_WIDTH: \\          OTHERPROPERTIES=&rdquo;RightFormat=(FLOAT, '%,8.1f')&rdquo; \\          *** IMPORTANT: The %,8.1f is surrounded by single quotes;

  • How to use NODIM func with out it's values being rounded

    I created a new calculated key figure in Query Designer 3.x, and used the function NODIM() - Value with out dimensions. When I use this function, the values are rounding off to the nearest value.
    For example, I have a value 0.000075 US$, when I use NODIM function the value is displayed as 0.000080. Value is getting rounded to nearest value.
    I tried using absolute value it did not work.
    Can any one tell me how to use NODIM function with out it's value being rounded to nearest value.
    Thanks,

    Hi,
    According to your description, you might want that "Notice" field has a default value when form is created and users can be able to change the value of that
    field.
    As a workaround, you can add an action rule in “Name” field via InfoPath to fill the default value in “Notice” field only when “Name” field is not blank and “Notice”
    field is blank.
    Settings of the rule are as below, you can modify it based on your need:
    Here is a link about how to add an action rule in InfoPath form, you can use it as a reference:
    https://support.office.microsoft.com/en-us/article/Add-rules-for-performing-other-actions-5322d726-b787-4e5f-8d37-ba6db68b451d?CorrelationId=8a64c12f-aa60-4d90-b1f9-a44fcc4e74b5&ui=en-US&rs=en-US&ad=US
    Best regards
    Patrick Liang
    TechNet Community Support

  • Point nearest of all in an array

    Hello
    I am having two  2 D array of  elements. Array1 and Array2.
    I take a value from Array2 and calculate its distance from all the elements in Array1. I need to get the element which is at the shortest distance from it. How is it posible?
     I have made a VI.After calculating the distance how is it possible to check for the shortest and how to store that nearest value in an array??
     please have a look
    Thanks 
    Nghtcwrlr
    ********************Kudos are alwayzz Welcome !! ******************
    Solved!
    Go to Solution.
    Attachments:
    Nearest distance.vi ‏11 KB

    While I did not quite understand what kind of output you want, here's one possible solution that can probably point you in the right direction. Good luck!
    I assume you want the value of the nearest array element and I assume by distance you mean the 2D distance between the two points in the complex plane. Other interpertations would be to get the array indices of the closest value, for example.
    Message Edited by altenbach on 03-12-2009 09:19 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Nearest_distanceMOD.vi ‏14 KB
    Nearest.png ‏7 KB

  • Pivot table automatically rounding percentage value

    Hi All,
    I have pivot table column which shows percentage values for a area it is directly rounding the values to the nearest values that means if i am getting 4.43% rounding it to 4.00% so is there any way to just show the percentage value with out rounding it to the nearest value.
    Thanks

    Hi copter,
    You can do it in pivot view itself.follow this step by step process http://shivabizint.wordpress.com/2008/09/14/changing-the-precession-of-percent-of-columns-in-pivot-table-of-obiee/
    Cheers,
    KK

  • Rounding Excise values

    Dear All,
    To round off the excise values to the nearest value what needs to be done.Guide me.
    Regards,
    Milton.I

    Hi,
    In Tax on Goods Movements -> India -> Maintain Company code settings, there check the Rounding Off duty in Procurement.
    Cheers...
    Santosh

  • Excise invoice through J1IS transaction

    Dear Friends,
    At Manufacturing location, 1 unit of material for each Batch is issued for lab sampling. This is done through QA11 transaction with movement type 331.
    In Excise configuration, rounding off is activated and for all outgoing invoices, BED/ E CESS/ SE CESS values get rounded off to nearest value.
    While creating excise invoice through J1IS, since the quantity of material for lab Sample is very less and the excise duty values being calculated are negligible...Ex - 0.48/ 0.32.- for these values system is converting then as Zero. This scenario is applicable for various materials and for each unit for lab sample there is a material document generated.
    Excise invoice is created with reference to each of the material document and the values are being nullified due to rounding off.
    If we change the config settings and deactivate rounding off, then this will also have impact on outgoing excise invoices created through J1IIN transaction.
    Is there any possobility that I can consolidate all the material documents and then rounding off logic is applied on final value?
    Regards,
    Praveen.

    Hi,
    Deactivate the rounding in config and create the routine for rounding the values and assign it against the excise conditions in the pricing procedure as a alt calc type.
    Regards
    Sunil

  • Problem in cin(excise)

    Dear cons
    In case of Purchase orders with excisable tax code,the system is allowing to do invoice verification even if RG 23 Part 2 has not been updated.The system is automatically reversing the GR/IR Clearing account even if J1IEX has not been done.Earlier this check was there,but now it is not working
    Thanks
    nirupama

    Dear Lakshmipathi,
    Thanks for your reply, If I am not wrong 355 is rounding off rountine of excise values. as i told you mines is export pricing procedure my BED also in USD, which i can't do. If i do that even the rounding decimals when we converting to INR give lot difference.
    Second : Rounding nearest value function module
    In the background calculation when the system is calculating the assessable value, there we need to incorporte this with our won peace of code, but later on SAP bringing the original values somehow.
    in my case also INR 2 decimals only, system in the background it is considuring the 3rd decimal.
    do you have any other solution. please let me know.
    Regards,
    Raghava.

  • CIN : decimal problem in export excise invoice

    Hi all,
    I have issue, we are in export sales and we activated 5 decimal option for our customer.
    issue is  we made a export billing document with ref that export excise invoice.
    - in my billing doc ED exchange rate is 47.4  and the unit price is 1.63 $
    when i am converting to inr  below difference is comming
    qty       inr price  Asse val       BED         dif for assessable value
    10224    77.26     789906.24   31,596.25  20.45 
                             789926.69    31597                 =>  it is calculated on 77.262 how to avoid the 3 decimal when system is calculating the Assessable value for duty calculation. ????
    above is for one line item. like this i have multiple line item is the same invoice and the difference is huge.
    Thanks in Advance
    Raghava

    Dear Lakshmipathi,
    Thanks for your reply, If I am not wrong 355 is rounding off rountine of excise values. as i told you mines is export pricing procedure my BED also in USD, which i can't do. If i do that even the rounding decimals when we converting to INR give lot difference.
    Second : Rounding nearest value function module
    In the background calculation when the system is calculating the assessable value, there we need to incorporte this with our won peace of code, but later on SAP bringing the original values somehow.
    in my case also INR 2 decimals only, system in the background it is considuring the 3rd decimal.
    do you have any other solution. please let me know.
    Regards,
    Raghava.

  • How to round off quantity in inventory

    Hi,
    How to avoid decimal places for PC(Piece) in the goods movement transactions..  I have given 0 decimal places in CUNI transaction. It is working properly for Production Order during Conrimation but it is not working in Inventory transactions like MIGO, MB1C,MB1A....
    for example When I enter Unint of entry In Alternate Unit say '10 KG'  System Automatically Caliculates quantity in base unit in decimal places say 115.012 PC based on the conversion factor defined in material master.
    My requiremet is the base unit quantity PC rounded off to nearest value in as 115 (PC).
    The same thing is working fine for production order.
    please suggest me how to do.
    Thanks,
    Shekar

    this all depends on your conversion rate enterd in material master.
    if 115.012 PC  equals 10 KG.
    what do you actually want the system to do,
    it would now that you would get 115.012
    you want it to be 115,
    this would then mean that you have to modify the entered quantity from 10 to 9something
    Is it that what oyu want?
    you certainly cannot have 115 PC and 10 KG if you dont change the conversion rate in your material master

Maybe you are looking for