How to show empty groups in crystal? - crystal-reports

I have a report that shows items by goups.
Lets say he groups are:
In Inventory
In Process
When there is no data In Inventory, that row is not shown. any idea how to show a row with 0 inventory?

It sounds as though you are grouping on a field (such as stock item status), where there may be 0 rows returned for certain values of the field (such as In Inventory). The answer is to amend your query to right outer join to a lookup table holding all values of the grouping field, for example as follows:
select lu.status_value stock_item_status,
si.stock_item_status item_status,
si.stock_item_id,
coalesce(si.quantity,0) quantity
from stock_item si
right join stock_item_status lu
on si.stock_item_status = lu.status_value
This will now include a row returned for stock_item_status values with no corresponding stock_items, with null values for all of the stock_item fields.
If you were including a subtotal of stock_item.quantity values for each status, changing this to coalesce(...,0) should ensure that this null value is displayed as 0.

If I'm understanding you correctly, you've got a field {table.inventory} that holds the number of items in inventory that has a null value when the inventory is zero? When you group on this field you're not seeing the rows with null values in this field?
Crystal should still display those rows, just in a group with a null group name. To fix this you can go into the Group Expert -> Select the group in question -> Options -> Options tab -> Select 'customize group name field' -> and then specify a formula as a new group name field where you simply check to see
if isnull({table.inventory}) then 0 else {table.inventory}
Similarly, you can just create a formula that does this and group on that instead.

Related

Display the highest value in a same column in crystal report

I am trying to show the highest values in column B which is related to each uniqe reference.I've tried this formula but didn't work.
The Data
Output 01.03.2019
This is out put from the below formula
Blockquote
01.03.2019_1
Blockquote
enter[01.03.2019_2]5 image description here
Expected Output
whileprintingrecords;
stringvar dept;
if {baseevent1.Column B} = Maximum({baseevent1.Column B},{baseevent1.Referance}) then
dept:={baseevent1.Referance}
There is an easier way to achieve your goal with less formula usage and more grouping and sorting.
You will need 2 grouping levels. The top-most group will be Referance, and then below that group on Column B. Ensure that Column B is sorted from lowest to highest. By sorting this way, the very last detail record will always contain the highest value of Column B.
Then suppress both group header section, suppress the details section, and suppress the Column B group footer section.
Place data fields for Referance, Column B, and Formula in the Referance Group Footer Section.
By grouping and sorting in this manner, when you reach the footer section for your top most grouping, the values each field contains will always be the record that had the maximum value of Column B.
No need for any formula fields at all with this approach. :)
Just do be aware, that if you ever have a duplicate value in Column B within a Referance Group, then you are going to run into issues, as this approach will print only the values of the last record in the grouped data. However, even with a formulaic approach like you began with, you were still going to run into this issue should there be any duplicates in the composite key value created by concatenating Referance and Column B.

How to sort combo box by frequently used?

So, simple question, I have combo box in my database and I want items that I have selected most frequently to appear first the next time that I add a record.
I would suggest adding a Long Integer field to the table consituting the row source for your combobox, and incrementing the value held by such field either on the AfterUpdate event of the combobox, or following the main operation being performed by your form.
Then, sort the items in the combobox by this new field in descending order.
I assume that your combo box selects a lookup value in for a property (PropertyID) that is saved in a table (MainTable).
You can get the number of times this property has been selected with
SELECT PropertyID, COUNT(*) AS SelectedTimes
FROM MainTable
GROUP BY PropertyID
Now get the sorted lookup table by using this query as sub-query:
SELECT L.PropertyID, L.Name
FROM
LookupTable L
( SELECT PropertyID, COUNT(*) AS SelectedTimes
FROM MainTable
GROUP BY PropertyID) X
ON L.PropertyID = X.PropertyID
ORDER BY X.SelectedTimes DESC, L.Name
I'm also sorting by name in case two entries have the same count.
As usage may change over time, you should record the time when an item was selected. Then you can weight the usage, so recent usage of an item have higher weight than those items used, say, a year ago.
Then you can run a query to list the usage having the most recently used items at top:
Select Item, Sum(1 / DateDiff("h", [SelectedTime], Now())) As Usage
From ItemUsage
Group By Item
Order By Sum(1 / DateDiff("h", [SelectedTime], Now())) Desc
Of course, this linear weighting may be too simple. You can apply any math to the usage like square or log.

SSRS sum of distinct values

I want sum of only unique values in SSRS report.Is there any logic to achieve this.
this is what something like this sum(distinct value)
Thanks
Supposed you have a column named value in your query, you could do the following:
Add an additional column to the query of the dataset:
ROW_NUMBER() OVER (PARTITION BY [value] ORDER BY [value]) AS valueNr
Then, if you already have created a Sum field in the table, change the expression of the textbox to
=Sum(Iif(Fields!valueNr.Value=1, Fields!value.Value, 0))
Repeat this for every "distinct sum" calculation.
Yes. You use groups. At the top click the insert menu, then table, then Table Wizard. Pick your dataset and hit next. Now drag the column for the different types of items you want a distinct sum of into the Row Groups section. Drag your count column into the Values section. This should automatically turn it into Sum(ColumnName). You can click the down arrow to change the aggregate type (if desired). Press next and next and finish. Viola. You have a distinct sum for each specified field.

Suppress group based on if value exists in record

What I would like to do is either suppress a group or (if possible) write this in to a selection record.
The goal would be to display all records in the group if any one of the records in the group meet the requirements.
For example if my group has three records and my requirement is that one of the records have a specific value in one field. Then display all three records in that group. Otherwise, if none of the three have that value then suppress the group.
I know where I need to put the formula and I thought the following would work but instead it only gave me the records that met the requirement not the others that accompany it.
Placed in the suppress group formula field:
if {table.field} <> "1" then true else false
Any thoughts on this?
Looks like I got it figured out. Here's what I did:
Create a Formula Field to check if the value exists in the record as follows:
if {table.field} = "X" then 1
Create a Summary Field of the formula field just created and sum the total for the formula field effectively counting how many records in that group have the value sought after.
Go to Section Expert for the desired group and Suppress using the following formula.
if Sum ({#Formula}, {table.field_2}) < 1 then true

Crystal Report not sorting the group field in ascending order as it is set up to do

I have a report with three groups:
Project
RFI
Status
I am conditionally suppressing groups 2 and 3. In each suppress formula section respectively, it says
{?Sort}="RFI" (or "Status")
It does the suppression correctly. However, when it is sorted by Status, the status field is not in ascending order. Does anyone know hwy this would happen?
I can't choose a table in the Group Sort Order Formula either:
Suppressing report sections will have no bearing on how the records are sorted. A report will always have its records sorted from the outer-most group field to the inner-most group field. In your report, the records will first be sorted by "Project", then by "RFI", and finally by "Status" regardless of what you are or are not suppressing.
If you want to choose which field to sort the report by via a parameter, then you should create a formula field and sort by that instead. So something like: if {?Sort}="RFI" then {table.RFI} else {table.Status} but you'll need to get rid of your RFI and Status groups first.