Repeating a result on a line on the rows/lines below untill that result changes? - crystal-reports

Image showing problem
I want to know if there is a way of repeating the result of a column downwards until the change of result.
Attached image shows the problem.
I need 9.1stWC column to fill the number(which is actually a string) all the way down until that number changes.
The column is not null where the blank fields are (9.is null, shows this) so I'm going to have to write additional formulas to show I'm guessing.
I've used previous function but that only shows for the next line down then is blank after.
The replicate string function will go across the column not downwards.
I've looked at a stringVar but cant find a way of making this work on this report.
I'm reserved about grouping as I have a lot of other filters and by grouping I could possibly loose the sequence depending on what I group by.
My aim is to show WC which are equal to the current op line by doing a simple formula after I have managed to populate that column

I will assume your column is a field named {Result.WC}.
Try this:
Create a formula. Let's call it #LastWC.
Use this code in the formula:
shared stringvar sharedLastWC;
if not isnull({Result.WC}) and {Result.WC} <> "" then sharedLastWC := {Result.WC};
sharedLastWC; //returns
Replace the field by the formula.
The idea behind this is to set the shared variable when the field is not blank and not null. So, the variable will hold the last "filled" value.
I can't make a test with the purposed solution right now, but give it a try and make adjusts if you need. Tell me if it does not work.
If the first row can be empty, you may need to create an aditional formula do start the value of the shared variable in the header of the report.

Related

Group data based on different size

I am trying to make a report in which I need to show data based on Width groups. Below is an example of data & the required output. I'm unable to make a group which can give this required output. If someone can help please.
The easiest way to accomplish your grouping needs for this data set would be to create a new Formula Field that evaluates the values of the Width data field for each record to determine which group the record belongs within, then do the grouping on this new formula field.
You formula field will look like this.
Select {WIDTH}
Case 400 to 600 :
"G1"
Case 601 to 849:
"G2"
Case 850 to 1049:
"G3"
Default :
"Default text or error message text goes here"
You will likely need to adjust the integer values I'm used in the Case statements to evaluate the WIDTH field. The text that goes into the Default case is up to you. In fact, if it works logically with your needs, you could eliminate the Default case entirely, as it is not required. However, it is good practice to ensure the Switch statement always returns a value, even if that value is text to indicate that something unexpected occurred. This allows your users to easily recognize a bit of a data that may be out of range for the grouping of the report so the report can be modified or the data can be corrected, whichever is the most appropriate action.
The other 3 columns in your required output appear to just be counting the number of records within each group that have a diameter within a range. To get this output you can use Running Total Fields with a Type of summary of Count and then use the range of values in the Evaluate section. The Reset section will be set to On change of group evaluating the group created by the formula field above. You will want to put a sort order on the diameter field though.

Crystal Reports: price for latest transaction

I need to create a field to put on group footer #1 that shows the latest price by customer type. The grouping is item_ID (see below). So for example if there were transactions over time with varying prices to Factories and to Retail stores, it would only show the price for the last time that item was sold for a factory(I have a separate field for retail stores). I have tried a few things but nothing is working. For example:
On the detail level:
if {TRANSACTIONS.TRANDATE} = Maximum ({#FactoryTranDate}, {TRANSACTION_LINES.ITEM_ID}) then
{TRANSACTIONS_LINES.PRICE}
FactoryTranDate is basically: if customer type = factory then trandate. Then I created a max of this on group footer #1.
This appears correctly on the transaction line but if the last transaction for that item wasn't to a factory, it will be 0 on the summary line. I tried to do a Max of that detail level field but it doesn't come up for my summary fields, I am assuming cause it gets confused upon doing a summary of a summary?
Sounds like the problem you are running into is the column of data you are trying to print in the footer has multiple rows and you can't predict where the value you want might be within those rows. So by the time you get to the footer, it only has the value held by the last row that printed.
To get around this you would want to use a few formula fields to create variables that can be used to store the value you want from the correct row when it is printed.
I would plan to use 3 formula fields. One to initialize your variable and set it to a default value of zero. Place this formula field in the header that corresponds to your footer and this will ensure the variable exists and is reset to a default value for each grouped value in this header. The formula will look something like this:
WhilePrintingRecords;
Shared NumberVar price:=0.00;
The second formula will declare the same variable again, and it will also include some logic to know when to set the value of the variable. This formula field should be placed within the section that prints the detail records for the grouping. The formula would look something like this:
WhilePrintingRecords;
If <condition to evaluate> Then
Shared NumberVar price:={TRANSACTIONS_LINES.PRICE}
I'm not entirely sure what condition you will want to evaluate here though based on the information you've provided, but I suspect it will be along the lines of if customer type = factory. However, it should be a condition that is only true when you want to capture the price of the detail record within the grouping. If you have multiple cases where it might be true, then you will want to sort them in such a way that the one you wish to capture is printed last within the group. Since you stated that it should be the last factory price, then I would sort by Transaction Date and the variable will change its value with each record that has a true condition and will only keep the price from the one with the latest Transaction Date.
The third formula field is simply for printing the value of your variable in the footer. This field will be placed in the footer section and will display the value of the variable on your report. The formula for this field will look something like this:
WhilePrintingRecords;
Shared NumberVar price;
The formula fields used in the header and details sections can be suppressed if you don't want them to print on your report, but I would recommend waiting until you have the final value printed in the footer verified before suppressing them. This will allow you to see how the value of your variable changes as the report is generated if you are not familiar already with using variable in this manner. You may also want to read up on the scope of variables in crystal reports if this is a new topic for you. My suggestions here all use the SHARED scope, but there are also LOCAL and GLOBAL scopes. GLOBAL might work better in your case, but I tend to favor SHARED in examples such as these because they have the most broad scope. LOCAL definitely will not work for you here though.

Setting a condition so that no results are displayed if the condition is not met

I'm trying to have a chart be blank rather than showing results if the size of the data that populates the chart is too small. I have a variable ID in which each case has a unique value. In a case where I don't want any data to show if there are less than 10 cases, I figured I'd need to set up a calculated field that would do something like the following:
IF COUNTD([ID]) < 10 THEN ....
But I can't figure out what command to call so that it shows no data. Would anyone have a pointer?
You can create a calculated filed with calculation "COUNTD([ID])<10" .It would be a Boolean filter.Now drag and drop the calculation to the filter shelf and set it to either "TRUE" or "Exclude False".

Displaying multiple records in Crystal report as comma separated value

I have a view that I am using to display some information in Crystal report file. In some cases, view is supposed to return more than 1 record.
By default, in these cases, Crystal report take the last record and display that one. So, if I have two records with id A and B, I will see only the details of B.
I want to have an option where both A and B are displayed separated by comma.
E.g. if EmployeeDepartment in Employee table has two records (CIS, FINANCE) for employee A, then I want to see #EmployeeDepartment return "CIS, FINANCE" instead of just "FINANCE".
I have been trying to find a way to do this. Till now, I have gotten this far:
Base formula
Shared Stringvar store;
store:=store+{TBL_MR_Header.MRHD_Customer_Ref_No}+ ", "
Display formula
Shared Stringvar store;
store
When I run the report, base formula returns "B," instead of "A,B". Display formula on the other hand displays nothing.
I am unsure what I am missing here.
Edit:
I have created a query that returns the two value comma separated, in both records. So, both records display "CIS, FINANCE" instead of "CIS" and "FINANCE" respectively. Now, I have simple problem, how do I put this query in crystal report file? Only option I can find is to use that datasource expert tool but that does not allow updating query.
Edit:
I actually decided to go different route there. I tried putting the base formula in header and display formula in detail section, but that didn't work either. Turns out, one of my colleague tried a trick to solve similar problem. He used the C# code to call a T-SQL query, got the value in CSV format, and passed it as a parameter. It requires an extra trip to database, but it made it easier.

SSRS Aggreation on Calculated Field

I am trying to perform an aggregation on a calculated Field in SSRS and am getting the following error:
[rsAggregateReportItemInBody] The Value expression for the textrun 'Textbox43.Paragraphs[0].TextRuns[0]' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers
This is the formula I tried to use:
=Sum(ReportItems!PlanPurchPrice.Value, "Select_UCPUtilization")
In this Case PlanPurcPrice is also an Expression:
=First(Fields!PawPlanPurchPrice.Value, "Select_UCPUtilization")
Any suggestions on this would be greatly appreciated.
SSRS 2008 does not support the functionality you are looking for unless the report item is located in the header or footer (as is stated in the error message). I would, instead, propose two alternate solutions:
First Option
Place the calculation in your query (if possible) at which point you can then reference the field and the aggregate will work as desired.
Second Option
You essentially want to create the aggregate you're looking to return elsewhere in the report where it is directly connected to the Select_UCPUtilization scope, then reference the aggregated value elsewhere. Follow these steps:
Within the same scope as report item PlanPurchPrice, calculate a sum of the PlanPurchPrice. Name the textbox containing the aggregate something meaningful (e.g., Sum_PlanPurchPrice).
Reference that textbox directly wherever you were trying to use the ReportItems sum before (i.e., =ReportItems!Sum_PlanPurchPrice.Value)
Hide the workaround. Place the aggregate you created in an additional column or row attached to the Select_UCPUtilization scope. Turn the text white, turn off growth and shrinkage, and make the row very tiny (a pixel or two high).
Using the second option, the report item does exist (and is visible, which is important) on the report and contains the sum you are looking to return elsewhere.
Hope this helps. if this doesn't make sense, please reply via comment and I'll help you to the best of my ability.