Crystal Report formula to reset a count? - sql

I want to get the total qty of items sold by year by each part number. So far I have the following formula:
if {INVOICE_DATE} >= DateTime(2012, 01, 01) and
{INVOICE_DATE} <= DateTime(2012, 12, 31)
THEN Sum ({INVOICE_QTY)
Now, that formula just sums all the parts sold in that year. What I need is for it to reset the sum as it count through each invoice and by each part. How can I do this?

Your formula is not doing what you think it is. For each row in your report (I'll assume that this is by an Invoice_ID or something along those lines) this will simply display the grand total sum of {INVOICE.QTY} for all invoices in the report and will not change from row to row.
To get something that is like your image, you need to create a Cross-Tab object and configure it such that its rows are based on the Product_ID, the columns are based on Invoice_Date and set to be printed "for each year", and set the "Summarized Fields" to be the sum of {INVOICE.QTY}.

I guess you are not grouoing the report hence you are getting the grand total using that formula. What you can do is:
First create a group by Year and then by Part.
In details place your fields that need to be summed and supress the detail part.
Take sum in group footer 2 (For parts summary) and Group footer 1 (For year summary).

Related

Calculate matrix of values based on column and row totals

I have data that is broken into group totals (rows) and month totals (columns). I need to take the totals and calculate a value for each month within each group. From my screen shot I can find an monthly cell value for the quarter total with the formula
=INT($F3/3); this would ensure that all rows total correctly but does not address the requirement for all columns to total correctly.
For the screen shot I manually added the values to visualize the desired outcome
Group Calculation: (Jan+Feb+Mar)=Q1 group total
Month Calculation: (Group1...Group6)+Inventory = Monthly Total
In the "current result" screen shot the values total correctly by groups however the result is incorrect by month. For example 'Jan' totals to 159.
Current Result
I'm looking for assistance in a formula or vba that would allow the monthly values to total to the group and month total.
Desired Result
It sounds like you are looking to recreate a matrix from the totals of its rows and columns.
First, you need to remove the Inventory totals from the column totals, as those figures do not need to be calculated.
Then, you can get quite close to the answer with the formula =ROUND(RowTotal*ColumnTotal/OverallTotal,0). In this case, the formula in cell B2 would be =ROUND((B$8*$E2)/$E$8,0)
However, since there is rounding involved, you will notice that the values do not add up perfectly. For a matrix this small, your best bet would be to manually fix the problem values. To do so, add formulas to check which columns and rows are improperly totaled. Your check formulas should subtract the totals of each row and column from the desired row and column total. This reveals that cell B3 is the problem, as both column B and row 3 are misaligned.
You can change cell B3 to 48, which will then ensure that all columns and rows total properly. If you had a much larger matrix to solve, you could write some VBA code to automate the check of each column and row.

QlikView Conditional SUM current value

I have a pivot table with multiple rows dimensions (District, Region, Shop) and months in columns. I need to calculate sales Growth ((sales this month - sales previous month)/sales previous month). As You can see from formula, i need a value from previous month (previous column). I have a formula for testing:
Sum(Total {<District={'District1'}, [Month]={'2015 09'}>} Quantity)
With this formula i am able to get the value from previous column (lets say i am calculating growth in month 2015 10 and District1). The problem is, that i get a wrong value, when this formula is used in a row with different District.
Is there any way to get district value of current row and use it in a formula? I tried multiple variations like:
Sum(Total {<District={$(District)}, [Month]={'2015 09'}>} Quantity)
Sum(Total {<District={$<=District>}, [Month]={'2015 09'}>} Quantity)
but none of them work
There is no need to add District in the calculation. QV will aggregate to it automatically since District is dimension already.
If you want to aggregate all rows under each District to show the total quantity for the whole District then you can use the following expression:
sum( total <District> Quantity )
The picture below demonstrate the result:
Also you can check the QV help (c:\Program Files\QlikView\English.chm) for the Aggr() function as well. With Aggr() function the same result can be achieved with:
aggr( NoDistinct sum( Quantity ), District )

How can I get the Total field to display only once instead of on change of every group?

I have grouped my formula by my date field per month but why does it show in all the months (via lookup table)?
Perhaps there's something missing or wrong with my formula? This is its code:
(Sum ({tblDates.TotalFuelSales}) + Sum({tblDates.TotalMotorOilSales})) -
(Sum ({tblDates.TotalOperationalExpenses}) + Sum({tblDates.TotalMotorOilExpenses}) + Sum({tblDates.TotalFuelExpenses}))
Thanks!
Issue here is Sum ({tblDates.TotalFuelSales} will give you the grand total so for every date group you the same value... if you wish to get according to date grouping then your syntax shoukd be something like below.
Sum ({tblDates.TotalFuelSales}, {your date grouping})
Above is just an example check syntax when you apply... similarly apply to all fields in formula
If you dont you want to see the Total for each month then you should place #Profit formula on the Report footer. It is currently on the Group Footer section so it will show on change of every group.
I would do it this way:
1) Right click every field on the Group Header and Insert Summary (Sum) on the group footer for each field. So you have five Summary fields on the Group Footer section.
2) Put my Profit formula in the Report footer section, use those summaries in the formula to get my totals.
This is assuming you want Profit to appear only once.
You can skip doing the Insert Summaries part, and directly include the Sum({Fields}, {tbl.Date_group}) in your Profit formula.

How do I compute an average of calculated averages in MS reportviewer/rdlc?

I've searched here and elsewhere on the web and have not found this exact problem/solution.
I'm building an rdlc report using the MS reportViewer - the report I'm creating is based on an existing spreadsheet where the average price across 6 months is calculated individually for each month, then the average of those prices is calculated as the 6 month period average price. Whether I agree with that methodology or if it's correct is irrelevant, I just need to know how to get an rdlc to do this.
For example:
Month Price1 Price2 Delta
May-12 $31.54 $30.03 $1.51
Jun-12 $36.27 $34.60 $1.67
Jul-12 $44.19 $42.00 $2.19
Aug-12 $38.96 $37.06 $1.90
Sep-12 $36.89 $35.08 $1.81
Oct-12 $35.57 $33.97 $1.60
Average $37.24 $35.46 $1.78
(sorry for the lack of a screen snip, I'm new and the system won't let me post an image...)
I've created a tablix that does the monthly averages computation - I use a group in the table to group the 6 months of data by month (and then hide the hourly price data so you only see the month total row) but I'm stuck on how to calculate the bottom row of the table which is the average of each column. (the average of the averages is not the same as the average of all 6 months of prices from the underlying data - that's what I've learned in this process... IOW, that was my first solution :-) )
What I tried to do to get the average of the averages was give the month total cell a name, MonthlyAvgPrice1, then in the bottom row, used this expression:
Avg(reportitems!MonthlyAvgPrice1.Value)
As I kind of expected, this didn't work, when I try to run the report, it gets a build error saying "The Value expression for the textrun 'Price1PeriodAvg.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."
Hopfully I've explained this well, does anyone know how to do this?
Thanks!
-JayG
Actually it is not clear from the question that how are you in particular binding the data to the report items, But from the given information what I understand is that you can
Try like this:
Right Click the tablix row and insert a row below
In the cell where you want to have this Average of Averages insert the following expression
=Sum(Fields!Price1.Value)/6
and similarly insert expression =Sum(Fields!Price2.Value)/6 and =Sum(Fields!Delta.Value)/6 in the other cells where you want to display the Averages
Of Course, you will change the Field names Price1,Price2 etc to the fields that you are getting the values from.
HTH

How to group the formula field results in crystal reports

I want Number of cartons and Pieces currently available in the stock that are about to expire in next 30 days and this is calculated based on expiry date...I have used formula field on crystal report to calculate current stock like "stock.crtns_added - stock.crtns_removed" and "stock.pieces_added - stock.pieces_removed"....Now I want to group by item name, category and expirydate because based on these three columns there can be more than 1 entries in the database....I want that when there are more than one entries the formula should sum up all the cartons and pieces for same item of a category with same expiry date and on report it should display just 1 line showing available cartons and pieces that are about to expire
How can i do this?? How can I apply group clause on the formula field in crystal report to get sum of cartons or pieces for each item based on expiry date??
You can Insert Group for each group you want. You can nest the groups and put the formula inside the inner-most grouping and it should give you sums grouped how you want. You'll end up with something similar to this:
Report Header
Page Header
Group Header 1 (category)
Group Header 2 (item name)
Group Header 3 (expiry date)
Details
Group Footer 3 - summation formulas possibly go here
Group Footer 2
Group Footer 1
Page Footer
Report Footer