Grouping and Sorting by Odd and Even Numbers - crystal-reports

I am trying to create a report which has addresses in form of house Nbr and street Name. I want to group all address by street name and then order them by house nbr which is a string but should sort like a number. Ideally i would like the odd ascending and then the evens descending so that my list would look like
1,3,5,7,9 .... 8,6,4,2
How would i go about this ? I created first group on street name and then 2nd group on house number with a formula for sorting of nbrs
i created a Formula Field OddEven with
ToNumber({tbl_FarmMaster.sano}) MOD 2
but i am having hard time applying that to my group

Create two formulas like below. Let's call them oddFirst and negativeEven.
oddFirst formula:
ToNumber({tbl_FarmMaster.sano}) MOD 2 == 1 then
1 //it is odd
else
2 //it is even
negativeEven formula:
if ToNumber({tbl_FarmMaster.sano}) MOD 2 == 1 then
ToNumber({tbl_FarmMaster.sano}) //it is odd
else
-ToNumber({tbl_FarmMaster.sano}) //it is even, note the negative sign
Then create two groups to sort:
first by the formula oddFirst
second by the formula negativeEven
Show the {tbl_FarmMaster.sano} field.

Related

Tableau create unique max date

I Need to get the Unique value of Max([Date]).
I have this calculation for max date:
{ FIXED [City] : Max([Date]) }
Count :
IF[Max Date (Last Street)]= [Date]
THEN [Count Record]
Else 0
END
For Example:
City Date Street I get (Count) I Want (Count)
Miami 01/01/2019 1st 0 0
Miami 01/02/2019 2nd 0 0
Miami 01/03/2019 3rd 1 0
Miami 01/03/2019 4th 1 1
This would be a good situation to mix LOD calculations and Table Calculations. Your initial LOD function looks good, as it will find the complete max date per each city. From there, you can apply the concept of the calculated field you already have started and add a Table Calculation (Last()):
IF ATTR([Max Date (Last Street)]) = ATTR([Date])
AND LAST() == 0
THEN [Count Record]
Else 0
END
Note that the other portions of the calculated field are wrapped in ATTR() to make them into aggregations.
Once you add additional cities back into the data, you'll have to edit the table calculation by Right clicking on table calculation on view > Edit Table Calculation...
Take note of the fact that Specific Dimensions is selected and Restarting Every is changed to "City"
Final product should look like this:
Alternative Method:
If you'd like to purely use LODs and your street names always contain unique ascending numbers:
If Date = {Fixed [City]: MAX(Date)}
AND REGEXP_EXTRACT([Street],'(\d+)') = {FIXED [City], [Date]:
MAX(REGEXP_EXTRACT([Street],'(\d+)'))}
Then 1
Else 0
END
The above will essentially extract the number from the street then add it as a condition in addition to the MAX(Date) which already exists. Then the you will only get a 1 when both conditions have been met.
The end result will be the same as above.

Indicate more than one record with matching fields

How can I indicate multiple records with the same Invoice number, but a different Sales Person ID? Our commissions can be split into multiple Salespeople, so there can be two different Salespeople per an invoice.
For example:
Grouped by: Sales Person ID (No Changing this option)
These records are in the Group Footer.
Sales Person ID: Invoice: Invoice Amt: Commissions: (Indicator)
4433 R100 20,000 3,025 * More than one record on the same invoice with a different sales person
4450 R096 1,987 320
4599 R100 20,000 3,025 * More than one record on the same invoice with a different sales person
4615 R148 560 75
4777 R122 2,574 356
If your report has less than 1000 invoices, you may try something like this.
This will return true when a second ocurrence of the invoice shows up. Then you can make something like set the row background do red.
Global NumberVar Array invoices;
numbervar nextIndex := count(invoices) + 1;
if nextIndex <= 1000 and not ({Result.InvoiceNumber} in invoices) then (
redim invoices [nextIndex];
invoices[nextIndex] := {Result.InvoiceNumber};
true;
)
else false;
If you want to detect the first occurrence, you will need something more sophisticated.
I think a SQL Expression Field would be a good way to achieve the result you want. You already have an InvoiceNo in each row of data. You just need a SQL Expression Field that uses that INvoiceNo to execute a query to count the number of salespersons who get a commission.
Something along the lines of:
(
Select Count(Sales_Person_Id)
From [Table]
Where [Table].InvoiceNo = InvoiceNo
)
This will return an integer value that represents the number of salespersons who are associated with one invoice. You can either drop the SQL Expression Field in your Indicator column, or write some other formula to do something special.

Crystal Report Count if all Details are not 0

I have a report with a list of orders and their product lines
the order lines have Qty ordered, Qty Delivered and Qty Backordered.
the Group header is the Sales Order number, the Details are all the product lines on that sales order.
I want to calculate in the Report footer the count of all Sales orders that have a backorder on them only.
I can do "if sum of backorder <> 0 then 1 else 0" in Group footer, but i cannot sum the result of this, i get "This field cannot be summarized" because you cannot sum a sum.
is there another way i can achieve this?
for example:(report sample)
this example should be 1 in the report footer because only one of the orders has a backorder.
thanks
Create a new formula with following content and name it #SalesWithBackOrder (The formula doesn't need to be placed anywhere on the report):
If {backorder} <> 0 Then
{SalesOrderNumber}
Else
0
or if {SalesOrderNumber} is text then:
If {backorder} <> 0 Then
{SalesOrderNumber}
Else
""
Then count the number of distinct values of the #SalesWithBackOrder formula.
You can do this by creating a new formula with following content (put it in your report-footer):
DistinctCount ({#SalesWithBackOrder})-1 // -1 because order-number "0" respectively "" is a distinct value too.

Calculate value based on existence of records matching given criteria - FileMaker Pro 13

How can I write a calculation field in a table that outputs '1' if there are other (related) records in the same table that meet a given set of criteria and '0' otherwise?
Here's my problem explained in more detail:
I have a table containing 'students' and another containing 'exam results'. The 'exam results' table looks like this:
StudentID SubjectID Level Result
3234 1 2 A-
3234 2 4 B+
4739 1 4 C+
A student can only pass a Level 4 exam in subject 2 if they have also passed a Level 2 exam in subject 1 with a B+ or higher. I want to define a field in the 'students' table that contains a '1' if there exists an exam result belonging to the right student that meets these criteria and a '0' otherwise.
What would be the best way to do this?
Let us take an example of a Results table where the results are also calculated as a numeric value, e.g.
StudentID SubjectID Level Result cResultNum
3234 1 2 A- 95
3234 2 4 B+ 85
4739 1 4 C+ 75
and an Exams table with the following fields (among others):
RequiredSubjectID
RequiredLevel
RequiredResultNum
Given these, you can construct a relationship between Exams and (another occurrence of) Results as:
Exams::RequiredSubjectID = Results 2::SubjectID
AND
Exams::RequiredLevel = Results 2::Level
AND
Exams::RequiredResultNum ≤ Results 2::cResultNum
This allows each exam record to calculate a list of students that are eligible to take that exam as =
List ( Results 2::StudentID )
I want to define a field in the 'students' table that contains a '1'
if there exists an exam result belonging to the right student that
meets these criteria and a '0' otherwise.
This request is unclear, because there are many exams a student may want to take, and a field in the Students table can calculate only one result.
You need to do a self-join in the table for the field you want to check, for example:
Exam::Level = Exam2::Level
Exam::Student = Exam2::Student
And for the "was passed" criteria I think you could do an "If" on the calculation like this:
If ( Last(Exam2::Result) = "D" and ...(all the pass values) ; 1 ; 0 )
Edit:
It could be just with the not pass value hehe I miss that it will be like this:
If ( Last(Exam2::Result) = "F" ; 0 ; 1 )
I hope this helps you.

How can I order a group, based on a summary field of a subgroup

I have a report which has essentially
Order
OrderDetail 1
OrderDetail ..
OrderDetail n
These details can have parts and/or labour costs associated with them.
Currently, I group based on OrderId and then have the OrderDetail information in the details section of the report. This works perfectly.
However, now I need to group the Orders based on two criteria OrderType and LabourCost of the entire Order. I have put together a quick formula to determine order.
if(Sum({order.Labour}, {order.OrderId})> 0) then
if({order.type} = "type1") then 1 else 2
else
if({order.type} = "type1") then 3 else 4
Basically, if it should be sorted based on labour then on type. (the Sum({order.Labour}, {order.OrderId}) sums the labour grouping based on the orderid)
However when I go to the Group Expert and add the group by field to my formula and then preview my report it spins (I cancelled the preview after a minute). If I remove the Sum portion of the formula then it takes less than a second.
Is there a way to order this report?
How I would approach it:
First, create a sql-expresssion field that calculates the labor total for each order:
// {%TOTAL_LABOR}
(
SELECT Sum(Labour)
FROM OrderDetail
WHERE OrderId=Order.OrderId
)
Next, create a formula field:
// {#OrderGroup}
if({%TOTAL_LABOR}> 0) then
if({order.type} = "type1") then 1 else 2
else
if({order.type} = "type1") then 3 else 4
Finally, create a new group, based on the formula field, ensuring that it groups before the order group. You can suppress the group's header and footer if desired.