How to drop some rows in groupby based conditions - group-by

`df.groupby('Month').sum()
Quantity Ordered Price Each
Month
0 0.0 0.00 0.00
1 10903.0 1811768.38 1822256.73
2 13449.0 2188884.72 2202022.42
3 17005.0 2791207.83 2807100.38
4 20558.0 3367671.02 3390670.24
5 18667.0 3135125.13 3152606.75
I want to drop first zero value row. Help me please

Related

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

Select first value over threshold or max in group

I have data that looks something like this:
time
value
replicate
1
0.1
1
2
0.812
1
3
0.9
1
1
0.2
2
2
0.3
2
3
0.4
2
And I want to find the duration when the values first cross a threshold value and the first value, in this case let's say it's 0.8 for each replicate group. However if a group doesn't have any value greater than the threshold, just return the max value.
Wanted output would be:
duration
replicate
1
1
2
2
Is this even possible to do in a single query in Postgres?
Something like:
select time, max(value)
from ...
where value > 0.8
group by replicate,time
union
select time, max(value)
from ...
where value < 0.8
group by replicate, time

Tableau - How sum values with 12 last months

in Tableau I have a table with this form :
rows: Score.
columns:MY(month), sum(good), sum(bad).
This is the information when I use: month 201811
201611 201612 ... 201801 ... 201811 TOTAL
Score Good Bad Good Bad Good Bad ... Good Bad
1 3 0 7 3 6 3 2 1
2 5 1 1 1 1 1 4 4
3 10 3 2 1 0 3 3 3
I want to use a filter with 'Month' column ,when I filter month=201811, show since 201611 to 201711 (last 12 months) in Total column(Totals in Bad and Good columns) by Score.
Filter: 201811
Formula: sum(Good) and sum(Bad) since '201611' to '201711'
I trying "IF DATEDIFF('month', [Good], today()) <=12" but doesn't work.
Thanks for your help.
Try this:
If DATEDIFF("month",TODAY(),[Your Date Field],"Sunday") <= -12
then [Your Date Field] else null end
Then use that as your date column. The "Sunday" is supposed to be whatever you consider the starting day of the week. I wasn't sure what your date field is named so I named it "[Your Date Field]"

Crystal report output in one row

I want to show multiple row in one row based on a Time. same this example
Same this :
time type1 type2 type3 type4
1.......2.5.......3.......2.5.......0
2.......2.........2.......0.........0
3.......3.........0.......0.........0
4.......1.9.......0.......0.........0
5.......2.........0.......0.........0
6.......2.1.......0.......0.........0
This my record table below:
time type value
1 1 2.5
1 2 3
1 3 2.5
2 1 2
2 2 2
3 1 2
4 1 1.9
5 1 2
6 1 2.1
I insert formula field for each field had this code
if ({type}=1) then
{value}
I get this row had 0 and other row had the real value.

take sum of similar column from multiple data table based on unique id in crystal report

I have four datatables like
Table 1
id name Afee Insfee
1 a 100 10
2 b 100 10
Table 2
id name Bfee Insfee
2 b 100 10
1 a 100 10
3 c 100 10
Table 3
id name Cfee Insfee
1 a 100 10
3 c 100 10
Table 4
id name Dfee Insfee
1 a 100 10
2 b 100 10
in the crystal report i want to get the result as
Name Afee Bfee Cfee Dfee Insfee total
a 100 100 100 100 40 440
b 100 100 0 100 30 330
c 0 100 100 0 20 220
where this INSfee should be the sum from all the four table for a particular ID and
total should be the sum of a row in that in that report.
How to do this in a sap crystal report.
To get the sum of Insfee, Create a formula and add the field (Insfee) from all tables using sign "+" and place it adjacent to afee, dfee... etc.
Now to get the total use below code:
Create formulas for all fileds(afee,bfee...etc) in below code I named those as a, a1,a1.
Now create a another formula for "total" and implement below code
Place the formulas in detail section, You will get result.
EvaluateAfter({#a});
EvaluateAfter({#a 1});
EvaluateAfter({#a 2});
{#a}+{#a 1}+{#a 2}