Conditional sum formula in Crystal reports - crystal-reports

I need a help to do sum in Crystal reports:
Here is the sample data:
Seq | Name | Score | used |Multiply|
1 | Name 1 | 60 | True | Yes |
2 | Name 2 | 70 | False | No |
3 | Name 3 | 56 | False | No |
4 | Name 4 | 45 | True | No |
5 | Name 5 | 55 | True | Yes |
6 | Name 6 | 20 | True | No |
7 | Name 7 | 80 | False | No |
8 | Name 8 | 75 | False | No |
9 | Name 9 | 90 | False | No |
10 | Name 10| 40 | True | No |
11 | Name 11| 60 | False | No |
12 | Name 12| 50 | True | No |
I need to calculate sum of TOP 4 rows (Where score is higher) and "Used"= true and if "multiply" = yes then score multiply by 2. and display in group header.
(Row1 x 2) + Row4 + (Row5 x 2)+ Row 12
Like (60 x 2 ) + 45 + (55 x 2 ) + 50
Please help
I have added global variable at top group and set to zero. Then sum and conditions in details area. It works well but I need to show result in Group header 1. Sum works fine and show correct values in details section and footer but I want to show total on top. I found that whilereadingrecords or sub report may work here, but dont know how to use either

Related

create line plot from table in tableau

I've got data that look similar to this
+------------+--------------+---------+---------+---------+---------+
| funding_id | amountOnHand | rate_1d | rate_1w | rate_1m | rate_1y |
+------------+--------------+---------+---------+---------+---------+
| USDOIS | 100 | 18 | 9 | 12 | 2 |
| USDOIS | 106 | 3 | 6 | 16 | 2 |
| USDOIS | 103 | 1 | 7 | 5 | 15 |
| USDOIS | 108 | 1 | 11 | 11 | 13 |
| JPYOIS | 100 | 0 | 19 | 16 | 15 |
| JPYOIS | 106 | 9 | 10 | 10 | 5 |
| JPYOIS | 103 | 4 | 9 | 11 | 6 |
| JPYOIS | 109 | 9 | 18 | 14 | 2 |
| EUROIS | 104 | 3 | 6 | 19 | 6 |
| EUROIS | 103 | 3 | 11 | 19 | 3 |
| EUROIS | 104 | 9 | 1 | 8 | 15 |
| EUROIS | 107 | 18 | 4 | 1 | 5 |
+------------+--------------+---------+---------+---------+---------+
I create weighted rates per funding id using the aggreation: SUM([rate_1d]*[initial])/SUM([initial])
And then use tableau to create a text table and get something similar to the following table (note that sometimes an entire row is null. that's ok)
+------------+------------------+------------------+------------------+------------------+
| funding_id | weighted_rate_1d | weighted_rate_1w | weighted_rate_1m | weighted_rate_1y |
+------------+------------------+------------------+------------------+------------------+
| AUDOIS | 3.0 | 8.0 | 6.0 | 3.0 |
| CADOIS | 20.0 | 3.0 | 17.0 | 0.0 |
| EUROIS | 9.0 | 0.0 | 19.0 | 7.0 |
| GBP CORP | | | | |
| GBPOIS | 12.0 | 19.0 | 14.0 | 16.0 |
| JPYOIS | 10.0 | 7.0 | 18.0 | 3.0 |
| USDOIS | 19.0 | 7.0 | 5.0 | 7.0 |
+------------+------------------+------------------+------------------+------------------+
What I'd like to do is create a line plot showing time on the x axis (so 1d/1w/1m/1y) and rate on the y axis, with each line colored by funding_id
Is there any way to do this?
Go to data source pane -> Select the measures weighted rate 1d, 1w, 1m etc..,
-> Then right click and select pivot this would convert column data to row data i.e.., pivot field names and pivot field values
-> Go back to your worksheet and drag the pivot field names to columns shelf and pivot field values to rows shelf, within the marks card change the chart type option from automatic to line chart and you're done.
Add more aesthetics to your chart as per your requirement.
Hope this helps.!
The solution is to use the "measure name" and "measure value" fields at the bottom of the "dimensions" and "measures" panels in the data selection area (no need to create a table at all)
so the steps are:
1) create 4 aggregations (weighted_rate_1d, etc)
2) create a new worksheet
3) drag Measure Names (found under Dimensions) to the Columns shelf
4) right click it, and filter out everything except the aggregations
5) drag "Measure Values" to the rows shelf
6) in the "marks" area just to the left of the plot (where you can change color, shape, etc) use the drop down menu to change the bar plot to a line plot
7) just below this, you'll see the measure values listed in green boxes- drag them around to reorder to it goes 1d, 1w, 1m, 1y (by default, 1w and 1m are switched because they're in alphabetic order)
8) drag funding_id to the color panel

Doctrine GROUPBY with SELECT MAX

Here is my table :
id | place | date | valid
1 | ONE | 10/12/2019 | true
2 | ONE | 11/12/2019 | true
3 | ONE | 12/12/2019 | true
4 | ONE | 13/12/2019 | false
5 | ONE | 14/12/2019 | false
6 | TWO | 10/12/2019 | true
7 | TWO | 11/12/2019 | true
8 | TWO | 12/12/2019 | true
9 | TWO | 13/12/2019 | true
10 | TWO | 14/12/2019 | false
11 | OTH | 10/12/2019 | true
12 | OTH | 11/12/2019 | true
13 | OTH | 12/12/2019 | true
14 | OTH | 13/12/2019 | true
15 | OTH | 14/12/2019 | true
I'm trying with doctrine and the QueryBuilder to get the id's of my table.
I need to get the id's of the MAX date by place where valid is equal to "true".
With the data's displayed, I want to get this result :
3 | ONE | 12/12/2019 | true
9 | TWO | 13/12/2019 | true
15 | OTH | 14/12/2019 | true
I tried some query builder but I can not get the results I wanted.
$qb = $this->createQueryBuilder("o");
$qb->select('o.id, o.place');
$qb->addSelect($qb->expr()->max('o.date').' AS maxDate');
$qb->andWhere($qb->expr()->eq('o.valid', true));
$qb->groupBy('o.place');
I also tried with a subquery but I have a problem to group the place, get the max date and return the ID 3 / 9 and 15.
How can I get the max date and group my lines by place please ?
Thanks

Dynamic groups in Postgresql data

I have a PostgreSQL 9.1 database with a table containing measurement data, which contains setpoint information. For example temperature setpoints. The measurements are taken when at a setpoint, after which the following setpoint will be set. A setpoint can be reached multiple times, e.g. -25, 25, 75, 125, 75, 25 degree Celcius. In this case 25 and 75 degree Celcius are reached multiple times.
Now I want to group the data per setpoint, but not group data together of another setpoint that has the same value but is reached at a later point in time.
Example data:
| id | setpoint | value |<dyn.group>|
| 1 | -25 | 5.324 | 1
| 2 | -25 | 6.343 | 1
| 3 | -25 | 6.432 | 1
| 4 | 25 | 3.432 | 2
| 5 | 25 | 4.472 | 2
| 6 | 25 | 6.221 | 2
| 7 | 75 | 5.142 | 3
| 8 | 75 | 7.922 | 3
| 9 | 75 | 3.832 | 3
|10 | 125 | 8.882 | 4
|11 | 125 | 9.742 | 4
|12 | 125 | 7.632 | 4
|13 | 75 | 5.542 | 5
|14 | 75 | 2.452 | 5
|15 | 75 | 1.332 | 5
|16 | 25 | 3.232 | 6
|17 | 25 | 4.132 | 6
|18 | 25 | 5.432 | 6
Normal group by clauses will fail, because setpoint can be there multiple times, but should not be put together.
Looking with LEAD and LAG to the previous/next values is also not desired, because changes will most likely be similar (e.g. if setpoint 75 is repeated, then most likely the step from 25->75 will also be repeated).
The expected outcome is the 4th column (<dyn.group>). With that column I can for example average on these groups.
It can be done with a custom aggregation function to generate the "group index" value and then a "group by" clause in that value.

Spotfire - Calculate average only if there are minimum 3 values

I want to create a cross table in Spotfire where in which Average is calculated only when there are at least 3 values. If there are no values or less than 3 values the average should be blank.
+-------+-----+---------+
| Month | Age | Average |
+-------+-----+---------+
| 1 | 10 | |
| 2 | 11 | |
| 3 | 2 | 7.7 |
| 4 | | |
| 5 | 13 | |
| 6 | 14 | |
| 7 | | |
| 8 | 19 | |
| 9 | 20 | |
| 10 | 21 | 20 |
+-------+-----+---------+
If I'm understanding you correctly, you want to group by Month, and then have something like this as your aggregation:
If(Count()>2,Avg([Age]),null) as [AverageAge_3Min]

Split postgres records into groups based on time fields

I have a table with records that look like this:
| id | coord-x | coord-y | time |
---------------------------------
| 1 | 0 | 0 | 123 |
| 1 | 0 | 1 | 124 |
| 1 | 0 | 3 | 125 |
The time column represents a time in milliseconds. What I want to do is find all coord-x, coord-y as a set of points for a given timeframe for a given id. For any given id there is a unique coord-x, coord-y, and time.
What I need to do however is group these points as long as they're n milliseconds apart. So if I have this:
| id | coord-x | coord-y | time |
---------------------------------
| 1 | 0 | 0 | 123 |
| 1 | 0 | 1 | 124 |
| 1 | 0 | 3 | 125 |
| 1 | 0 | 6 | 140 |
| 1 | 0 | 7 | 141 |
I would want a result similar to this:
| id | points | start-time | end-time |
| 1 | (0,0), (0,1), (0,3) | 123 | 125 |
| 1 | (0,140), (0,141) | 140 | 141 |
I do have PostGIS installed on my database, the times I posted above are not representative but I kept them small just as a sample, the time is just a millisecond timestamp.
The tricky part is picking the expression inside your GROUP BY. If n = 5, you can do something like time / 5. To match the example exactly, the query below uses (time - 3) / 5. Once you group it, you can aggregate them into an array with array_agg.
SELECT
array_agg(("coord-x", "coord-y")) as points,
min(time) AS time_start,
max(time) AS time_end
FROM "<your_table>"
WHERE id = 1
GROUP BY (time - 3) / 5
Here is the output
+---------------------------+--------------+------------+
| points | time_start | time_end |
|---------------------------+--------------+------------|
| {"(0,0)","(0,1)","(0,3)"} | 123 | 125 |
| {"(0,6)","(0,7)"} | 140 | 141 |
+---------------------------+--------------+------------+