How to select last record or first record value in a formula?

Post Author: d111
CA Forum: General
I am using a query in a report that in addition to other columns, has a column of month labels like:
There are no unique identifiers or sequence fields that can be used.   There is only 4 columns: the label and 3 percent columns.
Jan07Feb07Mar07Apr07etc.
I would like to show the range of months I am using in a label on the report showing the last and first records value. like: "Jan07 to Jun07".
I can not see how to use the functions maximun or minimum since it sorts the months alphabetically.
I would like to use a formula to just grab the first and last record.  I can't seem to find any information on this anywhere.
Please advise and thanks.

Post Author: bettername
CA Forum: General
Hmm... I suspect what you actually want is the minimum and maximum dates in the report, rather than the first and last records (even if they do happen to come out in date order). So you need to convert the text dates to real ones, and then pick the min/max values.
If so, try these:
Formula "ConvertToDate" (for details section) which converts your text field into a real date - suppress it once placed!:
//Since you have 2-digit years, this conversion assumes that all your dates are >=year 2000
numbervar the_month;if left({YourTable.YourField},3) = "Jan" then the_month:=1 elseif left({YourTable.YourField},3) = "Feb" then the_month:=2 elseif left({YourTable.YourField},3) = "Mar" then the_month:=3 elseif left({YourTable.YourField},3) = "Apr" then the_month:=4 else
//...etc etc you fill in the rest!
if left({YourTable.YourField},3) = "Dec" then the_month:=12;
date(tonumber("20"+right({YourTable.YourField},2)), the_month, 1);
Formula "Show Date Range" (for anywhere on the report) to show the min/max values of the dates;
totext (minimum({@ConvertToDate})) + " to "+totext(maximum({@ConvertToDate}))
If, however, you really just want the first and last records, and you want it at the top of your report as a title (eg: in the Report Header), then I can't see how it can be done without using a subreport that looks at the same dataset, but only displays the first and last records (using the formulas below).
Stick this in the details section, and call it "HoldRecords" and suppress it:
whileprintingrecords;stringvar first;stringvar last;if recordnumber = 1 then first:={YourTable.YourField}; //if its the first record that crystal is displaying, store it in a variableif recordnumber = count({YourTable.YourField}) then last :={YourTable.YourField} //and again, but for the last record
Now create another formula, and put it into the report footer:
evaluateafter({@HoldRecords});stringvar first" to "stringvar last //will display "Jan07 to Apr07"
NOTE:  if you have the report ordered by anything, this'll throw the record numbering, and therefore the first and last records, therefore... urgh.
Hope this helps...

Similar Messages

  • How to select last year's first day

    Hi friends,
    How to get the last year's first day using sysdate as on sysdate
    this gives the current year's start date
    I need last year's start date like 01-jan-2010 as on sysdate
    thanks

    Another:
    SQL> select trunc(sysdate-365.25,'YYYY') from dual;
    TRUNC(SYSDATE-365.25
    01-JAN-2010 00:00:00Note: the .25 accounts for this query being run on the last day of a leap year e.g.
    SQL> select trunc(date '2012-12-31'-365.25,'YYYY') from dual;
    TRUNC(DATE'2012-12-3
    01-JAN-2011 00:00:00Edit: Note, this still isn't completely accurate and could give a wrong result. Better solution is to use the add_months function.
    Edited by: BluShadow on 06-Apr-2011 11:55

  • How to check if it is first record

    hi..
    i have a block with some items SL,STAFF, NAME..., of multiple record.
    while entering data, i want to check whether this record is first record....
    if it is firs record i have to know the SL of last entry from DB and based on that generate next SL.
    " just let me know how to check whether it is my first record ..????"
    thnx ..

    ManiKanchan wrote:
    it worked
    plz tell me one more thing..
    " how to get the value of a item of previous record...?"
    example.. to know the value of SL of previous record , i tried
    VARIABLE := Get_Record_Property( GET_BLOCK_PROPERTY('BLOCK_NAME',CURRENT_RECORD)-1, 'BLOCK_NAME', :BLOCK_NAME.SL);
    But, did not work...help..!!!Why u thinking of this..
    Best way for sl generation is Sequence. try to use it.
    Other way write this at block-level trigger Pre-Insert
    SELECT NVL(MAX(AD_ID),0)+1 INTO :CUST.AD_ID FROM ACC_DTL;but this isn't good idea.
    Red this Auto generate Invoice Number
    Hopes this helps
    If someone response is helpful or correct, please mark it accordingly.

  • How to get fourthly row (row4) first column value (col1) in matrix

    Hi to all,
    In FMS, how to get fourthly row (row4) first column value (col1) in matrix in document.
    select $[$38.1.4]
    But it display the first row
    Please give me hint.
    Thank you

    Hi Eric,
    FMS may only apply to current row.  There is no way to get any other fixed row.
    Thanks,
    Gordon

  • I am working in Numbers and can't seem to change the generic value assigned to the legend.  Any advice on how to select the legend and save new values?

    I am working in Numbers and can't seem to change the generic value assigned to the legend.  Any advice on how to select the legend and save new values?

    Ntenich,
    If your table has a Header and your Legend text is in the header, it will be picked up by the table.
    Jerry

  • How to select different Querys based on Variable Value

    Hi guys i need to know how to select different Querys, based on variable values selected by the user, i try to do it using a Web Template but i don´t know how to program a Dynamic Query.....
    I hope sombody could help me with this
    Message was edited by: Oscar Diaz

    Hi Diaz,
    Can you explain the exact scenario which you are looking for!!!
    regards
    Happy Tony

  • How to select and store the dynamically clicked values in the checkboxes?

    Hi Gurus
    How to select and store the dynamically clicked values in the checkboxes?
    Scenario:-
    I am having a tree structure but I am not getting that user has clicked the which nodes.
    So how to do it.
    Pls.

    Hi,
    Once again, this is dependent on what your implementation expects. It would seem that your implementation is expecting all of the API to be coded in Java Card so it would make sense that you would load these packages like any other package. Loading an applet is not a special case, it just has an extra step of installing instances of it (and can actually be installed). Any other Java package just needs to be loaded. As such, just load your CAP files for each package of the API before loading any code that depends on it.
    Cheers,
    Shane

  • Internal table - move record to first record in table

    How can a move a record already in an internal table to the first record in the table? There is no appropriate sort that would make it the first record.

    Assuming the record is in the header:
    delete itab.
    insert itab index 1.
    That should be - assuming sy-index already points to the record you want to move.
    Rob
    Message was edited by: Rob Burbank

  • How does one generate random integers; first 5 values occur 2 times more than later values

    for the following code, how can I get the first 5 values to occur twice as often as the last 5 values?
    Do I have to use nested loops?
    Begin
      For n in 1 .. 10
      Loop
         dbms_output.put_line (ROUND(dbms_random.value(1, 10)));
    End Loop;
    End;

    Hi,
    If you had a lottery with 10 people participating, and you wanted to fix it so that each person had an equal chance of winning, what could you do?  One thing you could do is give tickets numbered 1, 2, 3, ..., 10 to the people, and then pick an integer in the range 1-10 at random.
    If you had a lottery with 10 people participating, and you wanted to fix it so that 5 of the people were twice as likely to win as the other 5, what could you do?  One thing you could do is to give 2 tickets to the first 5 people, but only 1 ticket to the other 5.  Since you have 15 tickets now, you'd pick a random integer in the range 1-15.
    Here's one way to do that in SQL.  The query below conducts 15 thousand lotteries.  We want the numbers 1-5 to get picked about 2000 times each, and the numbers 6-10 to occur about 1000 times each:
    WITH got_n AS
        SELECT  MOD ( TRUNC (dbms_random.value (0, 15))
                    , 10
                    ) + 1    AS n
        FROM    dual
        CONNECT BY LEVEL <= 15000
    SELECT    n
    ,         COUNT (*)    AS cnt
    FROM      got_n
    GROUP BY  n
    ORDER BY  n
    Sample output:
             N        CNT
             1       2048
             2       1939
             3       2020
             4       2066
             5       2007
             6        998
             7        967
             8       1004
             9        980
            10        971

  • How do I convert a string to a value in a formula

    I'm working on a home budget and I've imported my bank records. The records are apparently in a "string" format.
    I ultimately want to convert column D to positive integers and use those elsewhere. Simply creating a column that times the values by -1 should work. However I can't use this column in a formula because it contains a string.
    Copying a pasting the values still doesn't rid the string error message. In fact, in the new mavericks version, the option to "paste formula results" isn't an option: it's grey.
    Any help?

    try (just for fun) changing the "," to a "." (period)
    I think you localization (on your computer) doesn't match the localization of the values in column D
    Numbers automatically justifies an entry based on whe it thinks about the entry.
    In the example, above, I entered the text:
    "-123,45" in cell B14.  Numbers believes it is text and left justifies it.
    "-123.45" in cell B15.  Numbers believes it is a number and right justifies it.
    Since all your entries are left justified Numbers thinks they are text and are, therefore, NOT valid numbers.

  • How to "remember" data from the last or the first record printed on a page?

    I'd like to put a column value from the last record printed on the first page into a placeholder column (or whereever) to use later but I haven't found any way to do that. Trying the assignment statement with a placeholder in a format trigger causes "REP-1323: Cannot have output columns in format trigger...". Any ideas?

    Hi,
    SQL> select * from EMailNotify;
            ID TO_ADDRESS
             1 [email protected], [email protected],[email protected], ma.ram @test.com,[email protected]
             2 [email protected], [email protected],[email protected], ma.ram @test.com,[email protected]
             3 [email protected], [email protected],[email protected], ma.ram @test.com,[email protected]
    SQL> update EMailNotify
      2  set to_address=replace(to_address,' [email protected],','');
    3 rows updated.
    SQL> select * from EMailNotify;
            ID TO_ADDRESS
             1 [email protected],[email protected], ma.ram @test.com,[email protected]
             2 [email protected],[email protected], ma.ram @test.com,[email protected]
             3 [email protected],[email protected], ma.ram @test.com,[email protected]

  • How to select set of unique data records from internal table

    Hi
    I am looking for a command in order to select all unique data-records from an internal table without using a loop. Does anybody know a command that could do this?
    <b><u>An illustrating example:</u></b>
    <i>Example:
    Table content
    a 1
    a 2
    a 3
    b 1
    b 2
    c 1
    c 2
    c 3
    d 1</i>
    So I am looking for a command that should provide a, b, c & d for the first column or 1, 2 & 3 for the second column<b></b>

    Hi,
    SELECT DISTINCT  MATNR
                    FROM MARA
                   into table i_mara.
    Best regards,
    Prashant

  • How to select and sum  internal table records

    Dear Friends
    I kindly ask you if we have select statement
       if s_mtart = 'z003'
          select single pvprs from ckmlcr into ckmlcr-pvprs
    where poper EQ s_poper and
          kalnr = itab2-kalnr  and
          bdatj = itab2-bdatj and
          curtp = itab2-curtp.
    like this how can I calculate how many record it got and I want to get summation of this field(pvprs).And for all poper's must contain.
      Please  Let me remind you my itab is already open I didn't put any thing for this situation

    it seems to be you written this SELECT in a loop. if so,
    instead of pushing the values into ckmlcr-pvprs ,create an internal table
    data : begin of itab,
         pvprs  type ckmlcr-pvprs ,
        end of itab.
    then just after that SELECT SINGLE,
    select single pvprs from ckmlcr <b>into ITAB-pvprs</b>
    where poper EQ s_poper and
    kalnr = itab2-kalnr and
    bdatj = itab2-bdatj and
    curtp = itab2-curtp.
    IF SY-SUBRC = 0.
      APPEND ITAB.
    here either you can use APPEND OR COLLECT.
    If you use COLLECT,all the values will get summed up and final sum will be in the table ITAB-pvprs.
    ENDIF.
    After all loops your itab will have the totals.
    DESCRIBE TABLE ITAB LINES V_LINES.
    V_LINES Will have total no of lines.
    Regards
    srikanth

  • How to select LAST line from a SAP table?

    Hi developers,
    I need to select the last line from a SAP table, NOT from an internal table.
    Something like
    SELECT SINGLE LAST FROM pa00169..
    any help is more than welcome.

    Javier,
    Based on this statement from you:
    "i created a Z table, its a config table that stores some bussines rules, and an id counter, so in order to update that counter i need the last line of the ztable."
    I have one additional solution which is the "text box" approach IF the 'id counter' mentioned above is a numeric data type.
    If so, use an SQL function to get the highest value of ID_COUNTER.
    Then simply add one to it to produce a new, unique, higher-order primary key.
    See below:
    data: l_id_counter like ztable-id_counter.
    data: new_id_counter like ztable-id_counter.
    select max( ID_COUNTER ) from ztable into l_id_counter.
    new_id_counter = l_i_counter + 1.
    Now new_id_counter will be the unique, primary key IF this is the only field in ZTABLE's primary key.
    This will also GUARANTEE that your new record is built correctly.

  • T-SQL how to set last row as first

    Hi,
    I have the following query:
    SELECT leveltmp, 'Level ' + CAST( leveltmp as varchar(5)) + ' (' +
    STUFF((SELECT top(3) ', '+ BES.Name
    FROM BESTB BES
    WHERE BES.leveltmp = BE.leveltmp
    AND BESId=2
    FOR XML PATH('')), 1, 1, '') + ',...)' as 'level'
    FROM BESTB as BE
    WHERE BEId = 2
    GROUP BY leveltmp
    ORDER BY 1
    and I get the following results:
    1    Level 1 ( TestFirstLvl1, TestFirstLvl2, TestFirstLvl3,...)
    2    Level 2 ( TestSecondLvl1, TestSecondLvl2, TestSecondLvl3,...)
    3    Level 3 ( TestThirdLvl1, TestThirdLvl2, TestThirdLvl3,...)
    4    Level 4 ( TestFourthLvl1, TestFourthLvl2, TestFourthLvl3,...)
    5    Level 5 ( TestFifthLvl1,...)
    However, I need the last one always to be the first one, but the others to remain as they are. I need my order to be 5,1,2,3,4 instead of 1,2,3,4,5.
    So basically I need to get the following results:
    1    Level 1 ( TestFifthLvl1,...)
    2    Level 2 ( TestFirstLvl1, TestFirstLvl2, TestFirstLvl3,...)
    3    Level 3 ( TestSecondLvl1, TestSecondLvl2, TestSecondLvl3,...)
    4    Level 4 ( TestThirdLvl1, TestThirdLvl2, TestThirdLvl3,...)
    5    Level 5 ( TestFourthLvl1, TestFourthLvl2, TestFourthLvl3,...)
    Any idea on how to achieve this?
    Thanks

    create table #t (c char(1))
    insert into #t values ('a'),('b'),('c'),('d')
    select * from #t order by c ---now we need d to be first charachter 
    declare @c char(1)=(select top 1 c from #t order by c desc)
    select * from #t order by case when c =@c then '1' else c end
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

Maybe you are looking for

  • Difference between F-03 & FBL3N

    Dear All, One of the issue is when we seeing open items for three GL accounts which is related to bank account such as main, deposit & issue account in FBL3N, system showing the balance which is correct. Now my client clearing these deposit and issue

  • Linux and MSI KT4 Ultra : DVD problems

    Hi, I own an MSI KT4 Ultra Pure mobo.  The vt8235 Southbridge is supported in the lastest version of the Linux Kernel, 2.4.20 . After upgrading the kernel all seems to work fine, but when the system try to initialize my hdc (Secondary master of IDE,

  • Slider auto goes to "Off"

    I have a large HD hooked via firewire into a headless Mac Mini. Using Airport wireless, I've been able to back up 3 portables (plus the Mini itself) to this drive. However, I can no longer back up our Macbook Pro. Every time I attempt to choose the s

  • Conversion of DateTime to Duration

    Hi , How to Convert the DateTime Value (2011-02-19T03:39:51.051) To Duration Format (P1Y2M3DT10H30M) In BPEL . Any Help is Appreciated Thanks, Karthik

  • View Options Don't Stay Changed

    I can change my view options just fine. But if I exit LR and return, the View Options are back to where they started prior to my changing them. How do I make them sticky so they remain static between closing and opening LR? I use V1.4 and WinXP Thank