Printing Previous Record in Crystal Reports if Null Encountered - crystal-reports-2010

I have a report in which i have a formula (in crystal syntax) balance which is inserted in details section.formula is like:
WhilePrintingRecords;
Global CurrencyVar Balance;
if {table.cr}>0 or {table.dr} > 0 then
Balance:= Balance+ {table.cr} - {table.dr};
Balance
I want the report to print previous record for balance if table.cr and table.dr is null.Any help ???

Balance is the value that you are calculating locally...
To the extent I understand you need to use the previous value of {table.cr} and {table.dr}
if ISNull({table.cr}) and ISNULL({table.dr}) then
Balance:= Balance+ Previous({table.cr}) - Previous({table.dr});
Balance
Let me know if this is not your requirement

Related

SQL Server Reporting: How calculate value based on the previous calculated value int the same column?

I'm trying to calculate a row value based on the previous row value in the same column within a report expression. I can't precalculate this from database since starting point of calculation is dependent from input parameters and values in a table should be recalculated dynamically within report itself.
In Excel analogical data and formula look like as it is shown below (starting point is always 100):
B C D E
Price PreviousPrice CalcValue Formula
1 NULL NULL 100
2 2.6 2.5 104 B2/C2*D1
3 2.55 2.6 102 B3/C3*D2
4 2.6 2.55 104 B4/C4*D3
5 2.625 2.6 105 B5/C5*D4
6 2.65 2.625 106 B6/C6*D5
7 2.675 2.65 107 B7/C7*D6
I tried to calculate expected values ("CalcValue" is the name of column where expression is set) like this:
=Fields!Price.Value/ PreviousPrice.Value * Previous(reportitems("CalcValue").Value))
but got an error "Aggregate functions can be used only on report items contained in page headers and footers"
Can you please advice whether expected result is achievable in my case and suggest a solution?
Thank you in advance!
Sadly I'm still facing with issue: calculated column does not consider previous calculated value. E.g., I added CalcVal field with 100 as default and tried to calculate using above approach, like: =previous(runningValue(Fields!CalcVal.Value, sum, "DataSet1") ) * Fields!Price.Value/Fields!PreviousPrice.Value.
But in this case it always multiples Fields!Price.Value/Fields!PreviousPrice.Value by 100..
For example CalcVal on Fly always show 200
=previous(runningValue(Fields!CalcVal.Value, sum, "DataSet1")) * 2
https://imgur.com/Wtg3Wsg
I tried with your sample data, here is how I achieved the results
Formula to use, You might have to take care of null values
=Fields!Price.Value/(Fields!PreviousPrice.Value*Previous(Fields!CalcValue.Value))
Edit: Update to answer after Op's comment
CalcValue is caluated with below formula i.e on the fly
=RunningValue(CountDistinct("Tablix6"),Count,"Tablix6"*100
and then Final value as below
=Fields!Price.Value/(Fields!PreviousPrice.Value*
Previous(RunningValue(CountDistinct("Tablix6"),Count,"Tablix6"))*100)

Trying to generate an expression from a table based on table values

My SSRS report creates a summarized table. I need to do a calculation based on 2 pieces of data from the table and add it as an expression at the bottom of the report. My expression errors out as it is not reading the data output from the table.
I have followed up on all examples I could find with the error I get, but found no resolution. I am new to SSRS. I have tested the expression by simply using the IIf statement to return the values I'm looking for (without the rest of the calculations I need) and it doesn't return either value. I get "#Error" as the result. I have copied the lookup values directly from the SQL code, so I KNOW there are no typos in my comparison values.
I have this for the code in my expression:
=Code.Divide
(IIf(Fields!Results.Value = "BKR3 - Total Overtime Hours", Fields!Results.Value, 0)) ,
(IIf(Fields!Emp_Type.Value = "BKR1 - Total Paid Hours", Fields!Results.Value, 1))
Through another stackoverflow question I found this code and have added it to my report:
Public Function Divide(ByVal dividend as Double, ByVal divisor as Double) As Double
If IsNothing(divisor) Or divisor = 0 Or IsNothing(dividend) Or dividend=0 THEN
Return 0
Else
Return dividend/divisor
End If
End Function
I am getting this error:
The Value expression for the textrun
‘Textbox3.Paragraphs[0].TextRuns[0]’ contains an error: [BC30455]
Argument not specified for parameter 'divisor' of 'Public Function
Divide(dividend As Double, divisor As Double) As Double'.
This is what my output looks like:
*Emp_Type Results
*A3-Facility Payroll Hours 28,252.20
*A4-Provider Payroll Hours 1,998.50
*BKR1-Total Paid Hours 30,250.70
*BKR2-Total Worked Hours 27,037.62
*BKR3-Total Overtime Hours 504.20
*BS1-Hospital FTEs 99.72
*BS2-Clinic FTEs 23.25
Overtime % #Error
(I'm very sorry, I cannot get the list to indent!)
I am expecting this as my results:
Overtime % 0.18%
This is what I am getting instead:
Overtime % #Error

Tableau - Filter Dimension on Max Value of Measure

I'm trying to calculate the MAX value of column D of value E which resets for every A Column. Later I just need to show the MAX row of A.
Raw data looks like this:
The desired view would be like this:
Thanks!
This is an excellent example of a question which can/should be answered using LOD Calculations.
To start, find the maximum [Percentage] (Column E) per [Name] (Column B):
{Fixed [Name]: MAX(Percentage)}
Then insert that calculation, call it "Max Per Name", into another calculation which will only show the [Letter] (Column D) if the [Percentage] and the [Max Per Name] match:
IF [Percentage] = [Max Per Name] THEN [Letter] END
The result will be a dimension which shows the [Letter] which matches the largest [Percentage] and 'Null' when not matched.
From here, just filter out 'Null' - the result will be exactly as you desire. You will even be able to take [Percentage] off the view and still see an accurate [Letter].
Please note that while LOD Calculations are extremely powerful, they require a little more work to maintain and operate. They are a little more complex than normal calculations. Please take some time and read through this LOD Overview document to further familiarize yourself with their use/limitations.

SPSS Count function advice

Im having some issues with some SPSS code. Im new to SPSS and still trying to figure out the syntax. I'm trying to get my code to count the sum of two dice equal to 7. I cant get the count function to work the way I want it. Below is my code. Any tips would be greatly appreciated.
INPUT PROGRAM.
LOOP #I=1 TO 100000.
COMPUTE case = 1.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
EXECUTE.
COMPUTE Dice_1 = TRUNC (RV.UNIFORM(1,7)).
COMPUTE Dice_2 = TRUNC (RV.UNIFORM(1,7)).
COMPUTE total = Dice_1+Dice_2.
COMPUTE Number_Sum7= Dice_1+Dice_2 = 7.
COUNT Num= case TO Number_Sum7(1).
SAVE outfile = 'my file path'.
count function counts across a list of variables, in each line separately.
What you seem to be looking for is to count over rows.
You can start with:
frequencies total. /* see counts of all possible totals.
means Number_Sum7/cells=sum. /* count only the cases where total=7.
These will give you the answers in the output window.
If you want the answers in data for further analysis, look up the aggregate function.
For example, the following will give you the same results but in a new datasets:
DATASET NAME ORIG.
DATASET DECLARE freqs.
AGGREGATE /OUTFILE='freqs' /BREAK=total /Mycount=N.
DATASET ACTIVATE ORIG.
DATASET DECLARE only7.
AGGREGATE /OUTFILE='only7' /BREAK= /only7=sum(Number_Sum7).
Or, instead, you can add the results to your present data:
AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=total /TotalCount=N.
AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK= /total7=sum(Number_Sum7).

Highlighting mininimum row value in Pander

I am trying to display a dataframe in an RMarkdown document using the Pander package.
I would like to highlight the minimum value in each row of values. Here's what I have tried:
df <- replicate(4, rnorm(5))
df <- as.data.frame(df)
df$min <- apply(df, 1, min)
emphasize.strong.cells(which(df == df$min, arr.ind = T))
pander(df[1:4])
When I do this I get the error:
Error in check.highlight.parameters(emphasize.strong.cells, nrow(t), ncol(t)) :
Too high number passed for column indexes that should be kept below 6
I can print out the whole table (with the min column) without any trouble or I can print out a partial table without emphasis, but neither of these is ideal. I want the highlighting, but I do not wish to include the 'min' column.
I imagine the fact that I am leaving some highlighted cells out of the pander command is causing the error.
Is there a way around this? Or a better way to do this?
Thanks.
Subquestion: What if I wanted to highlight the minimum in the first few rows and the maximum in the next few. Is that possible in a single table?
Instead of the which lookup, with the possibility to match row minimums in the wrong rows, you can easily construct those array indices with a simple sequence (1:N) and calling which.min on each row, eg with apply:
> df <- replicate(4, rnorm(5))
> df <- as.data.frame(df)
> emphasize.strong.cells(cbind(1:nrow(df), apply(df, 1, which.min)))
> pander(df)
----------------------------------------------
V1 V2 V3 V4
----------- ----------- ----------- ----------
0.6802 0.1409 **-0.7992** 0.1997
0.6797 **-0.2212** 1.016 0.6874
2.031 -0.009855 0.3881 **-1.275**
1.376 0.2619 **-2.337** -0.1066
**-0.4541** 1.135 -0.1566 0.2912
----------------------------------------------
About your next question: you could of course do that in a single table, eg rbind two matrices created similarly as described above with which.min and which.max.

Resources