Auto adjust column size, position if some columns null - crystal-reports

I have a simple report with about 20 columns. Some of these columns might be empty. Here's what I am trying to do:
Check if a column is empty.
If it is empty, then readjust the position and size of rest of the columns
to fill up the gap.
Repeat steps 1-2 for every column.
I have some ideas of where to start with but not sure how to move forward.
I can check if a column is empty by :
If DistinctCount({#SomeField}) > 0
I also know that the width and position can be changed by the formatting formulas. But how do I put this together? That is, what logic would run to check and expand the columns and where do I put this logic? Should I be using global variables?
Any suggestion would be helpful.
Thanks
Note: I am using Crystal Report XI

Try this approach:
WhileReadingRecords;
Global booleanVar col1Empty := True;
Global booleanVar col2Empty := True;
...
if not IsNull({dbtable.col1}) then
col1Empty := False;
if not IsNull({dbtable.col2}) then
col2Empty := False;
Then use this global variables in suppres formulas.
Then count how many are not empty can calculate the average column width.

Related

Set column default value in Google Sheets

I have a finance tracking worksheet that has a number of formulas for each row. What I'd like to add is have these formulas replicate whenever a new row is inserted (fill it with a "default value").
Sheet before adding the row:
Sheet after adding the row:
I'd like some of these cells (B28 in this case) to contain a formula. for this row the formula is:
=IF(ISBLANK(C27), "", CONCATENATE(YEAR(C27), "-", MONTH(C27)))
You might want to consider an ArrayFormula. Here's a place for getting detail. In your case, the big trick is knowing that you can run the formula through all of Column C using the notation something like C1:C. Doing it this way is far more self documenting than burying it in a Google function and it's way more general.
Because the formula is the same for all rows, I added a function that just does the following:
function addRow() {
SpreadsheetApp.getActiveSheet().getRange('B7:B').setValue('=IF(ISBLANK(C7), "", CONCATENATE(YEAR(C7), "-", MONTH(C7)))');
}
I set this function to run on a trigger whenever the sheet is edited. The row numbers increment themselves so not problem there either.
Used this SO question for help: Default cell values when Inserting new row in Google Sheets
delete everything in your B column and paste this into B1 cell:
={"Date", ARRAYFORMULA(IF(C2:C<>"", YEAR(C2:C)&"-"&MONTH(C2:C)))}

Crystal Reports - columns line displayed on the last page even there are no records

I have used the following code in a formula in order to count the records:
Shared NumberVar PageofLastField;
If OnLastRecord then PageofLastField := PageNumber;
Also, for page header, I have used the following code in a formula in order to suppress report header if there are no records:
Shared NumberVar PageofLastField;
PageofLastField := PageofLastField;
IF pageofLastfield <> 0 and PageNumber > PageofLastField
THEN TRUE
ELSE FALSE
But still, on the last page, the lines between columns are displayed like a dot (please see printscreen). Can anyone help me? Thanks
Make sure this is not the case with your report.
this happens when you have drawn a line in header section but there is a small portion coming out to the next section. just drag the end point to the same section where the line was started in. This should solve it.

How to replace crosstab cell's value with a string

I have column fact, it can carry some difference values:
- Positive values - real values, need to be outputted as is
- 0 is null, output as is
- -1 - special value. Need to ouput "VAC" string in cell.
- -2 - special value. Need to output "SICK" string in cell.
I tried to do it with editing dimension, i replace it with:
case
when [BaseEmp].[FACT_VALUE] = -1 then 'VAC'
when [BaseEmp].[FACT_VALUE] = -2 then 'SICK'
else to_char([BaseEmp].[FACT_VALUE])
end
But now I see error: ORA-01722 invalid number (i think, because strings cannot be aggregated). In column properties I select "min" as aggregate function.
How to replace my special values with strings?
You don't need to change value to VAC, SICK etc.
You need to change DISPLAYED value.
Unlock the padlock in RS.
Select text in your cell
Set text source to "Report Expression"
Write expression like
CASE
WHEN cellValue() = -1 THEN 'VAC'
WHEN cellValue() = -2 THEN 'SICK'
WHEN cellValue() = 0 THEN ''
ELSE cellValue()
END
I tried thinking of a work around regarding your problem. I'm not really sure what you crosstab looks like but considering your parameters above, try creating a data item which holds your case condition for your fact.
Ex.
case
when [BaseEmp].[FACT_VALUE] = -1 then 'VAC' <--- this will produce Any Error Characters
when [BaseEmp].[FACT_VALUE] = -2 then to_char([BaseEmp].[FACT_VALUE]/0) <--- this will produce Missing Value Characters
else to_char([BaseEmp].[FACT_VALUE]) <---- as is
end
Then set the data item's Data Format to number and set the values for the properties as follows:
Kindly give this a try and hopefully it can somehow resolve you problem. Cheers!
Nikita Kuhta checkout Alexey's Baturin's answer. I think it's the appropriate approach. Just one thing if you unlock and select the text in the cell, all of the cell values will be selected and affected by the report expression. You might have several columns or other fact items in the crosstab. If that's the case, what you can do is
Unlock the Report.
Select the crosstab cell/intersection you want to change.
Set the Define Content to Yes.
Drag a Layout Calculation in the crosstab cell/intersection, then insert your case statement.
Thanks to a friend who told be about the define contents. :D

if dsum is blank then insert 0

I am trying to sum text boxes in a form within access 2010.
Within the text boxes I am summing there is the dsum function. The query is time dependent and will be updated throughout the day. This causes some boxes to be empty at points throughout the day.
I need to input a zero so I can sum the total in another box but I am having trouble.
Here is what I have tried so far.
= IID(Dsum("[field_name]", "[table_name]", "[time]='08'") = '', 0, _
Dsum("[field_name]", "[table_name]", "[time]='08'"))
I have tried it with single and double quotes around the zero and single and double quotes around the 'If blank' may be I haven't got the right permutation? Please help its driving me nuts!
DSum returns a Null, if the condition is not met. So try wrapping it in Nz(). Something like,
= Nz(Dsum("[field_name]","[table_name]","[time]='08'"), 0)

Hide or show image based on column values

I'm working on a report in which I need to show or hide images based on the values of a column. E.G: if the value 18 doesn't exist in the "Details" section, the image 18 must be hidden as described in the attached photo
I tried to use an array in which I inserted the values of the column I need to use. This is the supress expression I tried to use.
shared numbervar array MyArray;
MyArray:=makearray({MyTable.MyColumn});
local numbervar i;
local booleanvar result = true;
for i:=1 to ubound(MyArray)
do
if (MyArray[i] = 17) then
result := false;
result
I realize that the images aren't hidden because I'm working on the Page header and I can only access the first line of the table.
Because you're suppressing the images in the page header, you're limited to simple aggregate functions and won't be able to use variables, running totals, etc.
It's not hard but it is tedious because you'll have to create one new formula for each value.
//#CheckValue1
if {table.value}=1 then 1 else 0
//#SuppressionValue1
// If this evaluates to 'true' anywhere in your report, including the PH,
// you know value 1 does not appear in your report
maximum({#CheckValue1})=0