How to summarize the data generated in crystal report - crystal-reports

I have created a Crystal report whose sample output is below:
C_name P_name Code P. Rev F. rev C.rev
ABC AAA ABC-1-1 100 1100 1100
ABC AAA ABC-1-2 200 1200 1200
ABC AAA ABC-1-3 300 1300 2300
XYZ BBB XYZ-1-1 200 1200 2200
XYZ BBB XYZ-1-2 150 1150 3150
DEF CCC DEF-5-1 400 1400 1400
DEF CCC DEF-5-6 100 1100 2100
DEF CCC DEF-5-9 200 1200 4200
DEF DDD DEF-8-11 300 1300 2300
DEF DDD DEF-8-12 400 1400 400
Now, I want to add up the values for max value of Code. For example, ABC have 3 codes out of which ABC-1-3 is the latest code. So I want to dsiplay one record for these 3 records and add up the revenue values for 3 records and display it in one row only. The final output should look like below:
ABC AAA ABC-1-3 600 3600 4600
XYZ BBB XYZ-1-2 350 2350 5350
DEF CCC DEF-5-9 700 3700 7700
DEF DDD DEF-8-12 700 2700 2700
Please help..
Thanks

you can insert Group and P_name is the Group field which you select to create your group then in Running Total Fields and create new field for each of P.Rev F.rev C.rev in Evaluate and Reset part click on change of group and chose Type of summary Sum and for the Code field do the same,just chose Type of summary maximum. now you can add new fields to your Group and see the result.

Related

Merging two dataset in Stata with inconsistent ID

I have 2 dataset as follows:
input province municipality year str5 muni_name population
1 1 2000 AAA 1000
1 2 2000 AAB 5000
2 1 2000 AAC 1500
2 2 2000 AAA 3000
3 1 2000 AAA 5600
end
input province municipality year str5 muni_name population
1 1 2010 AAA 2000
1 2 2010 AAB 6000
10 5 2010 AAC 3500
10 6 2010 AAA 7000
11 1 2010 AAA 6000
end
In each dataset, observations are uniquely identified by the combination of province and municipality. However, the value of the province or municipality may change depending on the year. Technically, province 2 municipality 1 in year 2000 is the same as province 10 municipality 5 in year 2010. We can tell this by the same muni_name. However, the challenge arises because muni_name does not uniquely identify the observation. In fact, there are municipality name that is found in multiple province (AAA is found in province 1, 2 and 3 in year 2000).
I'd like to have the final merged dataset as follows:
input id year str5 id_name population
1 1 2000 AAA 1000
1 1 2010 AAA 2000
1 2 2000 AAB 5000
1 2 2010 AAB 6000
10 5 2000 AAC 1500
10 5 2010 AAC 3500
10 6 2000 AAA 3000
10 6 2010 AAA 7000
11 1 2000 AAA 5600
11 1 2010 AAA 6000
end
I'd like to have the merged data to be uniquely identified by province, municipality and year. For the conflicting province municipality code, I'd like to replace the province municipality with the most recent year.
What is the best way to do this? My current idea is as follows: Ideally, I'd like to consider a match to be 'perfect match' if province, municipality and muni_name all coincides (AAA and AAB in province 1 corresponds to this). Among the observation that are not 'perfect match', I'd like to match by non-duplicate muni_name (let's call this semi-perfect match). In this example, AAC corresponds to this.
Lastly, for duplicated muni_name (AAA) that is not 'perfect match', I'll match based on the province of other perfect match or semi-perfect match. Note that AAC and one of the AAA is in the same province. Since AAC is matched to province 10 in 2010, AAA in the same province should also be matched to province 10 in 2010.
How can I code the following match strategy in Stata?

How to roll numbers up in Tableau for aggregation?

I have a data structure issue. I have a problem where I need to roll up my data within tableau so that aggregated numbers do not skew in a certain manner.
Example of current data
ID Model_Number Value
123 fff 2
123 ggg 2
123 hhh 2
123 uuu 2
124 yyy 5
124 qqq 5
124 eee 5
Avg: NA 3.28
Ideal state of data and aggregation
ID Value
123 2
124 5
Avg 3.5
As you see since the data is at two different grains the aggregated number (avg) will be different. I would like to roll up my numbers to the distinct value of ID and then calculate my average which will result in a different (correct in my context) aggergated number.
Here is one calculated field that could help.
{ FIXED [ID] : AVG([Value]) }
This will give you the avg value by ID. You can then use a grand total(avg) to get the 3.5

Filters and conditions in window functions in Apache Spark

I have a sample dataset like below
Name date Category transactionamount
Adam 1/1/2020 Mobile 100
Adam 1/1/2020 Tab 200
Bob 1/1/2020 Mobile 200
Adam 2/1/2020 Tab 200
Bob 2/1/2020 Mobile 200
Adam 3/1/2020 Tab 200
Bob 4/1/2020 Mobile 200
I want to sum transactionamount column over a rolling period of current and previous day , so my code for window frame looks like below
val windowspec = Window.partitionBy($"name").orderBy($"date".asc)
val range = windowspec.rangeBetween(-1, 0)
val aasum2 = sum('transactionAmount).over(range)
df.select('date,'name,aasum2 as 'aasum).orderBy('date,'name).show(100,false)
This works fine for general summation without condition.
But I want output like below table with two new columns based on category column value.
Every output row should contain summation value for distinct date and name.
How we can apply condition(based on value of other column) while doing window function over a column
date Name Mobile_sum Tab_sum
1/1/2020 Adam 100 200
1/1/2020 Bob 200 0
2/1/2020 Adam 0 400
2/1/2020 Bob 400 0
3/1/2020 Adam 0 600
3/1/2020 Bob 0 0
4/1/2020 Adam 0 0
4/1/2020 Bob 200 0
Add your additional column to your partitionBy() within your WindowSpec

Crystal reports merge duplicate columns same data

Is there a formula for this:
mainId productId groupId product price qty
456 123 555 book 10 2
456 789 555 book 10 2
222 125 888 pencil 20 5
222 125 859 pencil 20 1
it shows (from sub report to main report):
product: book
Computation: 10x2 20
product: book
Computation: 10x2 20
Total 40
I want the result to be like this if data produce are the same like the one above:
product: book
Computation: 10x4 40
Total 40
if not the same data like with the mainId 222 the result should be like this:
product: pencil
Computation: 20x5 100
product: pencil
Computation: 20x1 20
Total 120
In sub report I group it by productId
Group Header: [Group#1 Name]
Details:
Group Footer: [product]
Computation: [computation (10x2)] [total (20)]
In main report I group it by productId too. I group the Subreport in Group Header. In the Page Footer is the Grand Total which is 20.
looks like you should group on GroupID rather than productid?

Crystal Report will not sum the duplicated record

I'm working in Crystal Report 2008, And I have a data with like this:
Date KG MT SQM
--------------------------------------------
01-01-2013 25000 25
01-01-2013 15000 15
01-01-2013 15000 15 -----(duplicated)
01-02-2013 13000 13
01-02-2013 12000 12
01-03-2013 18000 18
01-03-2013 33000 33
Then I tried to group it by date so the output is like this: so it's already removed the duplicated and sum the vlaue without a problem.
Date KG MT SQM
--------------------------------------------
01-01-2013 40000 40 55000
01-02-2013 25000 25 25000
01-03-2013 51000 51 51000
TOTAL 116,000 116 131,000
Then I want to add the SQM, and when I sum it, it will sum all the record in the group also with duplicated record.
(if you will sum the 3rd field, it also included in sum the duplicated record should be only '116,000' and not '131,000')
My question, how can I suppressed if duplicated and at the same time it will give me summary of the group to show the correct value?
Thanks,
Captain16