Shared DateVar in Subreport and datediff calculation in Main Report?

Hello experts,
I am using CRXI sp2.  I have a report that contains two subreports for different dates in the same date field that are identified by a Service Code.  The subreports have been placed in the same group footer 1a to be displayed and the calculation resides in the main report group footer 1b.  The shared variables are as follows:
whileprintingrecords;
shared datevar Codedate5473;
Codedate5473:={@Codedate5473};
and
whileprintingrecords;
shared Datevar Codedate5623;
Codedate5623:={@Codedate5623}
The main report has the following calculation is in group footer 1a.
Whileprintingrecords;
Shared numbervar daysbetween;
if (isnull({@Shared 5623})or isnull({@Shared 5473})) then 0
else daysbetween:= datediff("d",{@Shared 5623},{@Shared 5473})
This returns negative numbers as well as calculations where one of the shared variables is null.
I reset the calculation in the report header as well.
Thanks for your help in advance.
Kevin

Hi Kevin,
I can reproduce your issue, As per my knowledge the crystal will make some issues in null value computation as well as  shared variable  computation
In your report i can see , you tried to access values from subreport to main report through shared variable. that will make problem. we can access values from main report to subreport without any issue using shared..dont ask me the reason..i am not the right person to say that... lol.
The another wrong thing  i was found in your formula is , you are not resetting the shared variable any where.. so once the date field is null, the shared variable returning the previous value.
So this is the solution for you..
1,You have to add one more subreport for displaying your result., Lets say 'Sub report3'
and create a formula, like.(Same which you have write before for the result)
shared datevar Codedate5473;
shared Datevar Codedate5623;
numbervar daysbetween;
WhilePrintingRecords;
daysbetween:= datediff("d",Codedate5473,Codedate5623);
daysbetween;
2, Re- write your first two formulas like this
For Subreport1,
WhilePrintingRecords;
shared dateVar Codedate5473;
if isnull({Codedate5473}) then
Codedate5473:=date(0,0,0)
else
Codedate5473:=date({Codedate5473});
For subreport2
WhilePrintingRecords;
shared dateVar Codedate5623;
if isnull({Codedate5623}) then
Codedate5623:=date(0,0,0)
else
Codedate5623:=date({Codedate5623});
Hope this will works for you,
Cheers,
Salah.
Edited by: salahudheen muhammed on Aug 7, 2009 1:05 PM

Similar Messages

  • How to change unlinked subreport with a newer version without having to delete and recreate in the main report?

    I am using crystal reports version 11 and have inherited a report with 5 sub reports. Here we version the each report that contains changes. Is there a way that I can change the pointer for the sub report to the latest version? The person who gave me these reports stated that he deleted the old sub report and inserted the new sub report. The issue with doing this is you lose all you positioning and have to perform these tasks again. This seems like a lot of work especially if the upgrade to the sub report was only cosmetic. If I could update the link with the new report name it would make things easier.
    Appreciate any assistance and thank you

    I had a similar situation where i had 4 different main reports that has 20 sub reports each.
    Best steps i figured out to keep track is:
    1- I do not create a sub report on the fly. (origanlly- sub reports were built by "create a sub report with the report wizard"
    so First i save all the sub-reports independently, and gave them corresponding name to their data fetch.
    On inserting report as a sub report i used the option "Choose an Existing Report"
    2- Since i had 4 different report, i created 4 seprate folders for each report. And then Sub folders for Sub reports.
    3- Any changes in the sub report would have a different copy, and saved with the date stamp. In summary info, Comments section, I will type the update detail.
    For Formatting changes alone:
    I create a fake group inside the report and drop a Text box. The box would have comments about the formatting and suppressed  (only to seen at design mode).
    Hope this helps.

  • Use subreport total in formula in main report

    Hi,
    I have a subreport which is a total figure. I just want to muliply this by a number in a field on the main report, can this be done?
    Any help appreciated!

    Symptom
    A report contains a subreport. Data from the subreport is required for calculations in the main report.
    How can you share subreport data with the main report in version 7 (or higher) of the Crystal Reports Designer?
    Resolution
    Shared variables, introduced in Crystal Reports version 7, make it easier to pass values from a subreport to the main report. Using shared variables requires two formulas: one to store the value in a shared variable, the other to retrieve the value from the shared variable.
    The most important thing to remember when using shared variables is that Crystal Reports must first evaluate the formula where the value is stored before evaluating the formula that retrieves the shared variable.
    For example if you want to pass a grand total from the subreport to do a calculation in the main report, follow these steps:
    1. In the subreport, create a formula similar to the one below:
    //@SubFormula
    //Stores the grand total of the
    //{Orders.Order Amount} field
    //in a currency variable called 'myTotal'
    WhilePrintingRecords;
    Shared CurrencyVar myTotal := Sum ({Orders.Order Amount})
    2. Place this formula in your subreport.
    3. In the main report, create a formula that declares the same variable name:
    //@MainFormula
    //Returns the value that was stored
    //in the shared currency variable called
    //myTotal in the subreport
    WhilePrintingRecords;
    Shared CurrencyVar myTotal;
    myTotal
    4. Place @MainFormula in a main report section that is beneath the section containing the subreport.
    NOTE:======
    For the shared variable to return the correct value in the main report, you must place @MainFormula in a main report section that is beneath the section containing the subreport. This ensures Crystal Reports evaluates the @SubFormula before @MainFormula.
    One way to do this is to insert a section below the section containing the subreport, and place @MainFormula in this new sub-section:
    · On the 'Format' menu, click 'Section'.
    · On the 'Sections' list, click the section containing the subreport.
    · Click 'Insert' (at top of dialog box). This inserts an additional subsection.
    · Click 'OK' to return to the report, and insert @MainFormula into this new sub-section.
    The next time you preview the report, @MainFormula displays the value from the subreport. In this particular example, that value was the grand total of the {Orders.Order Amount} field.
    ============
    5. Once you have verified that @MainFormula is returning the correct value from the subreport, you can include this formula in other main report formulas, such as:
    //@NewFormula
    //includes data from subreport
    {@MainFormula}+ Sum ({Customer.Last Year's Sales})
    · Place this formula in the same section as @MainFormula, or in a section further down on the report.
    You have now successfully shared data from a subreport with the main report.
    NOTE: =====
    This is not possible with On Demand Subreports in Crystal Reports.

  • How To Suppress Records In Subreport Based on Value in Main Report

    I want to supress records in the Details section of my subreport based on a value in the Details of my Main report (main report could have same record as subreport).
    I created the following formula with a shared variable and placed it in the Details section of my main report:
    WhilePrintingRecords;
    Shared StringVar sCertCode :={ACCPASCERT.CERT_CODE}
    I placed the subeport in the Group Footer of the Main Report.
    In the subreport, in the Section Expert I added the following formula for Supress of the Details section:
    WhilePrintingRecords;
    Shared StringVar sCertCode;
    sCertCode = {ACCJBCERTS.PERS_CODE}
    Unfortunately even though the value in the main report is the same as the value in the subreport, those records are not being suppressed in the subreport.
    Would appreciate any ideas.
    Thanks.

    Thanks Zilla.
    The group is not based on Cert_Code but on another database field.
    I can try linking on the Cert_Code. But, how do you make the link "<" ">" when linking the main report and the subreport. I don't see that as an option?
    Edited by: Giulia Smyth on Feb 27, 2009 4:05 PM

  • Opportunity and metrics calculations used in reports

    Hi,
    Need to know how various entities are being calculated in the Opportunity and revenue matrices.
    Eg:- what's the formula being used to calculate Avg. Sales Cycle and Avg. Days in Stage etc.
    Any suggestions will be helpful.
    Thanks
    Nakul

    Hi Nakul,
    I know that for the Sales Stage report that each night when the ETL runs it takes a snap shot of the opportunities and what sales stage they are in (etc), and the Avg. Days in Stage is based off all the snapshots for how many days a opportunity was in a sales stage.
    I’m sorry though I don’t know what the formula’s are that are actually used to figure out 2 two metrics you asked about.
    Hope this helps.
    -Joe

  • Without using SubReport or SQL Command in Main Report, get desired results without duplicating

    It seems so simple.  I just need the cost, at a certain time (based on a parameter), for each item.  I wrote a SQL Command that works beautifully, but when it connects to the existing report, it slows to a horrible crawl and cannot be used for tables with over 4 million records.  Here is the SQL Command that provides the desired results:
    SELECT TOP 1 WITH TIES "INVENTITEMPRICE"."ITEMID", "INVENTITEMPRICE"."PRICETYPE", "INVENTITEMPRICE"."MARKUP", "INVENTITEMPRICE"."PRICEUNIT", "INVENTITEMPRICE"."PRICE", "INVENTITEMPRICE"."PRICEQTY", "INVENTITEMPRICE"."ACTIVATIONDATE", "INVENTITEMPRICE"."DATAAREAID"
    FROM ("AX09PROD"."dbo"."INVENTITEMPRICE" "INVENTITEMPRICE" INNER JOIN "AX09PROD"."dbo"."INVENTTABLE" "INVENTTABLE" ON (("INVENTITEMPRICE"."ITEMID"="INVENTTABLE"."ITEMID") AND ("INVENTITEMPRICE"."DATAAREAID"="INVENTTABLE"."DATAAREAID")))
    WHERE  ("INVENTITEMPRICE"."DATAAREAID"=N'TMC' AND "INVENTITEMPRICE"."PRICETYPE"=0 AND "INVENTITEMPRICE"."ACTIVATIONDATE"<={?As Of Date})
    ORDER BY ROW_NUMBER () OVER(PARTITION BY "INVENTITEMPRICE"."ITEMID" ORDER BY "INVENTITEMPRICE"."ACTIVATIONDATE" DESC)
    I've attached the report with saved data.  However, when I remove the restrictions of just certain items, it is unusable as it is SO SLOW!
    I can also get the desired results from using a subreport but it takes forever to export due to the number of records/items.  Whenever possible, I avoid subreports for this reason.  I've attached that report with data as well.
    Please be patient as I'm not savvy in SQL, but decent in generating reports.  What am I doing wrong?  This seems SO simple.  The premise is that I want the corresponding information based on the date entered:  If the date entered is 3/15/2014, the result should be 91.15 as indicated below.  I'd simply like this value to be placed in a formula per item.
    Item 80014:
    Activation Date
    Cost Price
    6/2/2014
    104.43
    4/1/2014
    91.58
    3/1/2014
    91.15
    2/1/2014
    92.89
    1/1/2014
    93.57
    Any assistance would be GREATLY appreciated!
    Thanks!
    Teena
    Update:  I was unable to attach the reports with .rpt or .txt extensions.  There were well under 1MB.  Any suggestions?

    hi Teena,
    if you're going the inline subquery route, try something like the following...the last line in the sub-query 'where' clause should in theory take care of matching the correct price based on relating the item id's between your cost price & inventory data. this should leave you with distinct values for each itemid then. hopefully it won't error out as i'm just guessing on the syntax.
    SELECT DISTINCT
    "INVENTTABLE"."ITEMID",
    "INVENTTRANS"."DATAAREAID",
    "INVENTTRANS"."DATEPHYSICAL",
    "INVENTTRANS"."QTY",
    "INVENTTABLE"."ITEMGROUPID",
    "INVENTTABLE"."ITEMNAME",
    "INVENTTRANS"."TRANSREFID",
    "INVENTTRANS"."STATUSISSUE",
    "INVENTTABLE"."ITEMTYPE",
    "INVENTTRANS"."TRANSTYPE",
    "INVENTTRANS"."RECID",
    "INVENTTRANS"."DIRECTION",
    SELECT TOP 1 "INVENTITEMPRICE"."PRICE"
    FROM "AX09PROD"."dbo"."INVENTITEMPRICE" "INVENTITEMPRICE"
    WHERE  "INVENTITEMPRICE"."DATAAREAID" LIKE 'TMC%'
    AND "INVENTITEMPRICE"."PRICETYPE"=0
    AND "INVENTITEMPRICE"."ACTIVATIONDATE"<={?As Of Date}
    AND "INVENTITEMPRICE"."ITEMID" = "INVENTTABLE"."ITEMID"
    ORDER BY "INVENTITEMPRICE"."ACTIVATIONDATE" DESC
    ) AS ITEMPRICE
    FROM  
    "AX09PROD"."dbo"."INVENTTABLE" "INVENTTABLE"
    LEFT OUTER JOIN "AX09PROD"."dbo"."INVENTTRANS" "INVENTTRANS"
    ON ("INVENTTABLE"."DATAAREAID"="INVENTTRANS"."DATAAREAID")
    AND ("INVENTTABLE"."ITEMID"="INVENTTRANS"."ITEMID")
    WHERE 
    "INVENTTRANS"."DATAAREAID" LIKE 'TMC%'
    AND (("INVENTTABLE"."ITEMGROUPID" LIKE 'RAW%') OR ("INVENTTABLE"."ITEMGROUPID" BETWEEN '000' AND '999') OR ("INVENTTABLE"."ITEMGROUPID" LIKE 'Ship_Box'))
    AND "INVENTTABLE"."ITEMTYPE" IN (0,1)
    ORDER BY 
    "INVENTTABLE"."ITEMGROUPID",
    "INVENTTABLE"."ITEMID",
    "INVENTTRANS"."DATEPHYSICAL" ASC
    Message was edited by: Jamie Wiseman

  • Summary field of subreport used in main report formula calculation

    I have a summary field in a subreport that I want to use in a calculation of a percentage using a second summary field in the main report as the denominator.  How do I do this in a new formula?

    Thank You Ian Waterman,...
    Couple of questions:
    Where you say "... in subreport
    @ eval
    whileprinting records;
    shared number x:=your summary
    Am I correct that this is to be a new formula created in the subreport design?
    What should I put for the "x" in the formula?
    Should the "your summary" be:  "DistinctCount of Activated_Survey.Seq.Incident"  which I have showing in the Report Footer of the subreport?
    Where in the subreport should I place the formula?  Can it be hidden?
    Where you say "In subreport header..."
    @reset
    whileprintingrecords;
    shared number x:=0
    Am I correct that this is to be a new formula created in the subreport design?
    What should I put for the "x" in the formula?
    Where in the subreport should I place the formula?  Can it also be hidden?
    Where you say "In the main report in section after subreport..."
    I have the subreport sitting up in the main Report Header as I only want the subreport summary field showing. 
    In the subreport, I have the Report Header and Details section hidden.
    @calc
    whileprintingrecords;
    (shared number x / main report summary) * 100
    Am I correct that this is to be a new formula in the main report?
    However, what I need to have happen is that the main report summary field of: "Count of Answered_Survey.Seq.Incident" needs to be divided by the subreport summary field of "DistinctCount of Activated_Survey.Seq.Incident" * 100.
    What do I modify in the formula?
    Thanks.

  • Get data in a subreport based on a shared variable from the main report.

    Goodd morning,
    My question/problem is how to manage this scenario.
    I am transfering 2 shared variables (pereiod from /period To, ) from the main report to a subreport and now  i would like to get data in this subreport based on these 2 variables...
    The problem is that i can not find the shared one in select expert icon...
    Could anyone point me to solve this issue?
    Thks for any help.
    Jose Marin
    Crystal Report XI SR3

    Hello Jos,
    I recommend to post this query to the [Crystal Reports Design|SAP Crystal Reports; forum.
    This forum is dedicated to topics related to the creation and design of Crystal Report documents. This includes topics such as database connectivity, parameters and parameter prompting, report formulas, record selection formulas, charting, sorting, grouping, totaling, printing, and exporting but also installation and registering.
    It is monitored by qualified technicians and you will get a faster response there.
    Also, all Crystal Reports Design queries remain in one place and thus can be easily searched in one place.
    Best regards,
    Falk

  • Need to supress main report based on shared value comes from subreport

    Hi,
    I have a database that is used in both main report and subreport. On main report I have column a,b ,c, d,e,f to display in detail section, the subreport (column c, g,h etc) is also displayed on detail section, the link between main report and subreport is column a,b and a formula based on the value of c. So the link is within one database, some records link with other records  and display both matching records on one line(especially column c shows one value in main report and another value in subreport). That's why I need subreport and I can display the report correctly.
    Here is my question: if one record in main report couldn't find a match in subreport (subreport is blank), then I would like to show this record; if one record in main report does find a match in subreport, I don't want it to show(need to be supressed). I can define a shared variable to flag whether the subreport is blank or not, but this shared variable has to be placed under the section of subreport in main report and I don't know how to supress the upper detail section with subreport in it.
    Any help would be appreciated!
    Helen

    Hi
    In this case you need to insert the same sub report twise.
    Example :
    Detail a--Insert the sub report and go in sub report suppress all sections and using shared variables bring the value to main report.
    Detail b -- based on detail a sub report suppress the main report records
    Detail c-- Your actual sub report will display the values.
    Note : use the same links for your detail 'a' sub report which you are using for detail 'c' sub report.
    Thanks,
    Sastry

  • How To Pass Data Between A Main Report and a Subreport

    Hello,
      I'm working with Crystal Reports Professional XI. 
      I have a main report with two date parameters: BeginDate of Date type and EndDate of Data type.  The main report has no details being printed instead it's grouped by a formula field and displays a summary count at the group footer.  I have  a subreport that is not linkable to the main report.  The subreport is grouped differently.  It has no detail records being printed and displays a summary count at the group footer as well.  The two reports are using the same tables with the same linking relationship.
       I created the same two date parameters in the subreport but this isn't right because when I run the report then I get four Date prompts: BeginDate and EndDate parameter from the main report and the BeginDate and EndDate parameter from the subreport.
      I'm not dong something right here.  What do I need to change in the reports so that l have the same record selecton being passed from the main report to the subreport record selection based on the BeginDate parameter and the End Date parameter from the main report?  Right now, the subreport is selecting all the records in the tables specified.
      Have a great day.  Any feedback would be greatly appreciated.
    Thanks,
    Ting

    Hi Jason,
       Thanks for replying to my posting.  It's been awhile since I've worked on Crystal Reports so I'm getting reacquainted with sub-reports again.  
        By linking the main report to the subreport by the BeginDate and BeginEnd parameters, will the date parameters be passed from the main report to the record selection for the subreport?  
       Also by doing your approach when the user is prompted to run the report, will it display on the popup window four date parameters: the BeginDate and EndDate from the main report and underneath that the BeginDate and EndDate from the sub report?  If so I'm trying to avoid that because it would be the same date range that I'm wanting to use for the main report and the subreport.  
        I hope that made sense.
    Thanks,
    Ting

  • Summarize data from a subreport in a main report

    Good afternoon,
    I'm trying to summarize data from a subreport with data in a main report and I can't get it to summarize all the data correctly. The reports are linked on order number.
    The main report has 3 groups - customer id, batch, order number (in that order). In the detail section I have product and amount. I have the group footer for group order numbers split into two. Footer A has the subreport.
    The subreport has tax code and amount in the detail and I've created a shared variable:
    WhilePrintingRecords;
    Shared CurrencyVar taxtotal := Sum ({@total tax})
    In my main report I created a formula for the shared variable:
    WhilePrintingRecords;
    Shared CurrencyVar taxtotal; taxtotal
    In Footer B of the order number group I have a summary field that is taking the shared variable and adding it to the product amount and creating a total.
    {@taxtotal1} +Sum ({@ext price}, )
    That is all working fine. Where my problem comes in is on the footer for the Batch group. There are 3 order numbers for 1 batch. I have this summary field in the Batch group footer
    ({@taxtotal1} +Sum ({@ext price}, ))
    But it's not calculating correctly. I need it to take all the product amounts and all the tax amounts and add them together, what it is doing is only adding one of the tax amounts along w/ all the product amounts.
    What am I doing wrong? Any help would be greatly appreciated.
    Jeannette

    Hi Jeanette,
    You need to have the running total accumulate into the Batch group as well.  Right now it's just getting the the Tax Total from the last Order Number. 
    In the formula in Footer B of the Order Number, change your formula to: 
    WhilePrintingRecords;
    Shared CurrencyVar taxtotal;
    CurrencyVar batchTaxTotal;
    batchTaxTotal := batchTaxTotal + taxtotal;
    taxtotal;
    Now in your formula in the Batch footer change it to: 
    WhilePrintingRecords;
    CurrencyVar batchTaxTotal;
    (batchTaxTotal +Sum ({@ext price}, {batch}))
    In the Batch Group Header, you will need to reinitialize the total to 0 for the next batch: 
    WhilePrintingRecords;
    CurrencyVar batchTaxTotal := 0;
    Good luck,
    Brian

  • Can we use shared variable in main report's crosstab

    Post Author: sangi
    CA Forum: General
    Hi,
    I have a main report with subreport (in Group footer), crosstab (in Group header).
    For cross tab calculation, I need a value from subreport to be passed to main report's crosstab.
    I could pass the value using shared variable.. but since the crosstab is in group header , I am not able to get the values .. .it is all 0....
    Please help me

    Post Author: wapper
    CA Forum: General
    To my best knowledge, what you ask for is impossible. The subreport in group footer is going to be evaluated during the last pass, so you are too late to get values into the group header. I could suggest creating a copy of your subreport and placing it (possibly hidden) into the group header just to get the values you need... But this would be the last measure if you really can't do anything else to achieve same goal. Wapper

  • Using a subreport formula in a main report formula

    Hello,
    I am trying to use a formula that is in the subreport and also a formula that is in my main report to come up with a percentage.
    ve researched the forums on the internet and couldn't find anything that directly fit my situation.
    - Formula #1: The SubReport formula is the "sum" of a number variable of {JobRecord.ProjectedIssueDate}. This is for the actual amount of job issued.
    - Formula # 2: The MainReport formula is the "sum" of a number variable of {JobHours.StartDate}. This is for the actual amount of jobs completed.
    Issue: I need to create a formula to take the Formula # 1 and Formula # 2 and get a percentage.
    Example:
    9 Jobs Completed in Main Report / 10 Jobs Projected in Sub Report = 90%
    My main report is grouped as follows for both the main and sub report:
    Grouping #1: Start Date
    Grouping #2: Contractor Code
    Grouping #3: Job Type Code
    I need this formula to work on the Grouping # 3 Level.
    Any takers?

    Also, If you want the Percentage and Sum from the Subreport to show beside each other, here's what you need to do:
    1) Create a new Group header 3b section
    2) Move everything except the Subreport on the Group Header 3b section
    3) Get inside the Subreport and suppress all sections of the Subreport
    4) Back in the Main Report reduce the size of this Subreport and make this no bigger than a dot. Reduce the size of the section so it doesn't take up a lot of space.
    5) Create a formula with this code:
    shared numbervar cnt;
    Drag and drop this formula on the Group header 3b so that this shows the sum from the Subreport.
    -Abhilash

  • Passing Array From Subreport to Main Report then Summing

    Hi,
    I am having troble passing an array from a sub report to the main repport.  I have managed to create the array, pass it and display it in the main report, however the first value of the array is displayed twice.  Here is the  formulae I have used:
    In the sub report:
    whileprintingrecords;
    shared stringvar str;
    str:=str{@value}","
    In the main report:
    whileprintingrecords;
    shared stringvar str;
    stringvar array arr;
    arr:=split(str,",");
    join(arr,",")
    Also, when I have managed to resolve the problem of the first value printing twice, I hope to change the array back to a number array and sum all of the values together.  I'm not too sure how to do this either.
    I hope you can help.
    Julie

    Ummm... Isn't Join(Split(str,","), ",") = str?  Why bother with the two extra lines of code?  Also, are you sure the subreport isn't creating the "duplicate first value"?  (I.e.  The data has the same value on two records, so it's being added twice?)
    Also if you're looking for the sum, why not create another shared variable and sum the value in the subreport as you're building the array (assuming you need the array for other purposes)?
    HTH,
    Carl

  • Can a subreport select records based on values in the main report record?

    Post Author: calvin
    CA Forum: General
    Perhaps my understanding of a subreport is incorrect as this is the first time I've used one, but it seems to me that the subreport should be able to use the values from the main report record in its (the subreport's) operations-but my subreport doesn't seem to be working that way.In my main report, I select a set of records from a 'request' table. I have a subreport in the detail section so the subreport is processed for each of the request records. That works, but I'm simply getting the same data reported multiple times. It's as if the subreport only uses the last request record rather than the current one. Stating it this way I can see that the problem might be evaluation time-it's processing the request records first, then processing the subreport, and only then printing everything. If this is correct then putting WhilePrintingRecords on the subreport should work-but the only way I know of to do that is in a formula. Can I call the subreport from a formula? Or am I totally off-track?Thanks.

    Post Author: foghat
    CA Forum: General
    Have you established a link(s) between your main report and subreport?When viewing the main report, click edit --> subreport links and link the 2 based on whatever values from the main report you want.

Maybe you are looking for