Suppress Group by Condition - crystal-reports

I've a crystal report like this:
Page Header
2013 & 2014 Salesman Performance Report
Group Header
Salesman: {Salesman}
Month 2013 2014
Details
{Month} {2013Amt} {2014Amt}
Group Footer
Total: {#2013} {#2014}
Result:
2013 & 2014 Salesman Performance Report
Salesman: Billy
2013 2014
Jan 1,000.00 0.00
Feb 500.00 800.00
Total 1,500.00 800.00
Salesman: Keith
2013 2014
Jan 0.00 0.00
Feb 0.00 0.00
Total 0.00 0.00
Salesman: Candy
2013 2014
Jan (200.00) 0.00
Feb 0.00 200.00
Total (200.00) 200.00
Is it possible to suppress the salesman group "Keith" if there're no transaction on 2013 & 2014?
Thank you for the suggestions from craig & Siva. There's a problem, if the total sum for a salesman is 0 but there're transactions. How to handle it?
For example:
Salesman: Kitty
2013 2014
Jan (200.00) 0.00
Feb 200.00 0.00
Total 0.00 0.00
I can have the finally result now although I'm not sure the method is correct or not.
Create formula field Count1 & Count2 and input the following formula
Count1: If {2013Amt} <> 0.00 then 1 else 0
Count2: If {2014Amt} <> 0.00 then 1 else 0
Then input the following formula into Group header, details and group footer (section expert> Suppress)
Sum({#Count1},{Salesman})=0 and Sum({#Count2},{Salesman})=0

You will be able to do so, but not with a running total field--running total fields can only be used in the footer.
Instead, add the following conditional-suppressional formula to the salesman header, salesman footer, and details sections:
Sum({2013Amt},{Salesman})=0 And Sum({2014Amt},{Salesman})=0

In this case you need to supress Group header, details and group footer.
Go to the section expert and gor to the forumula of supress then write below code.
If {2013Amt} =0 and {2014Amt}=0
then true
else false.
For group footer write condition on sum of the group.

Related

calculating excel formula using powershell

I am having below data in excel sheet (e.g. it's for 1 day and for 5 mins sample
So 2022-10-23 01:35:00 PM will have multiple rows, 2022-10-23 01:40:00 PM will have multiple rows and so on)
SLA sheet
SYMM_ID DATE INSTANCE Total Response Time Host MBs Read/sec Host MBs Written/sec Host Reads/sec Host Writes/sec
297900076 2022-10-23 01:30:00 PM L_PRDPRF 0.44 579.25 14.23 4405.09 142.27
297900076 2022-10-23 01:30:00 PM L_PRDPRF 0.26 29.89 0.97 4041.24 103.99
297900076 2022-10-23 01:30:00 PM L_PRDPRF 0.49 187.3 162.67 3779.49 7470.4
297900076 2022-10-23 01:30:00 PM L_PRDSTD 0.41 4.16 1.45 213.21 200.95
297900076 2022-10-23 01:30:00 PM L_NPRDSTD 0.53 0.01 0.03 0.03 3.31
297900076 2022-10-23 01:30:00 PM L_NPRDSTD 0.57 0 0.01 0 2.18
I am running the below formula and result I am getting in another sheet
=IFERROR(AVERAGEIFS(SLA!$D:$D,SLA!$C:$C,"*_L_*STD",SLA!$B:$B,$B20,SLA!$D:$D,"<>0"),"-")
The output of the above formula giving me 1 row. So for each date and time, the SLA sheet will have multiple rows but output is AVG of them as single row. so finally each date and time will have 1 row in other sheet.
for a 30 days month, the output sheet should have 122430 = 8640 rows ( 12 rows per hour, 24 hours a day and 30 day month)
The same I need to perform via powershell. I have done the formula part but the problem is I am not getting how to loop/perform that 8640 rows part
Please need suggestions on this. let me know if any details missed.

missing years - replace with empty row

I am tying to retrieve some data and it is as below:
id
year
value
1
2015
200
1
2016
3000
1
2018
500
2
2010
455
2
2015
678
2
2020
100
as you can see some years are missing - I would like to add the rows with missing years, null for column value and I want to do it per specific ids - any ideas?
You can combine GENERATE_SERIES() with a left join do expand the missing years. For example:
select x.id, x.y, t.value
from (select id, generate_series(min(year), max(year)) as y from t group by id) x
left join t on t.id = x.id and t.year = x.y
Result:
id y value
--- ----- -----
1 2015 200
1 2016 3000
1 2017 null
1 2018 500
2 2010 455
2 2011 null
2 2012 null
2 2013 null
2 2014 null
2 2015 678
2 2016 null
2 2017 null
2 2018 null
2 2019 null
2 2020 100

PostgreSQL - How can I SUM until a certain hour of the day?

I'm trying to create a metric for a PostgreSQL integrated dashboard which would show today's "Total Payment Value" (TPV) of a certain product, as well as yesterday's TPV of the same product, up until the same moment as today, so if I'm accessing the dashboard at 5 pm, it will show what it was yesterday until 5 pm and today's TPV.
edit: My question wasn't very clear so I'm adding a few more lines and editing the query, which had a mistake.
I tried this:
select
sum(case when table.product in (13,14,15,16) then amount else 0 end) as "TPV"
,date_trunc('day', table.date) as "Day"
from table
where
date > current_date - 1
group by date_trunc('day', table.date)
order by 2,1
I only want to sum the amount when product = 13, 14, 15 or 16
An example of the product, date and amount would be like this:
product amount date
8 4750 19/03/2019 00:21
14 7840 12/04/2019 22:40
14 15000 22/03/2019 18:27
14 11715 19/03/2019 00:12
14 1054 22/03/2019 18:22
14 18491 17/03/2019 14:28
14 12253 17/03/2019 14:30
14 27600 17/03/2019 14:32
14 3936 17/03/2019 14:28
14 19007 19/03/2019 00:14
8 9400 19/03/2019 00:21
8 4750 19/03/2019 00:21
8 25000 19/03/2019 00:17
14 10346 22/03/2019 18:23
I would like to have a metric that always calculates the sum of the product value today up until the current moment - when the "product" corresponds to values 13, 14, 15 or 16 - as well as the same metric for yesterday, e.g., it's 1 PM now, I want today's TPV until 1 PM and yesterday's TPV until 1 PM as well!

Using a join instead of subquery

For this question:
Get the pids of products ordered through any agent who makes at least one order for a customer in Kyoto. Use joins this time; no sub-queries.
I was able to get the answer using a subquery:
select distinct pid
from orders
where aid in (
select aid
from orders
where cid in(
select cid
from customers
where city = 'Kyoto'
)
)
I cannot figure out how to do this using only joins however.
This code returns the aid's that i need to get the pid's however i can't come up with a way to get them without using a sub query:
select distinct o.aid
from orders o, customers c
where o.cid = c.cid
and c.city = 'Kyoto'
Here are the two tables i am using:
Customers:
cid name city discount
c001 Tiptop Duluth 10.00
c002 Basics Dallas 12.00
c003 Allied Dallas 8.00
c004 ACME Duluth 8.00
c005 Weyland-Yutani Acheron 0.00
c006 ACME Kyoto 0.00
and Orders:
ordno mon cid aid pid qty dollars
1011 jan c001 a01 p01 1000 450.00
1013 jan c002 a03 p03 1000 880.00
1015 jan c003 a03 p05 1200 1104.00
1016 jan c006 a01 p01 1000 500.00
1017 feb c001 a06 p03 600 540.00
1018 feb c001 a03 p04 600 540.00
1019 feb c001 a02 p02 400 180.00
1020 feb c006 a03 p07 600 600.00
1021 feb c004 a06 p01 1000 460.00
1022 mar c001 a05 p06 400 720.00
1023 mar c001 a04 p05 500 450.00
1024 mar c006 a06 p01 800 400.00
1025 apr c001 a05 p07 800 720.00
1026 may c002 a05 p03 800 740.00

Ordering query Crosstab Postgres

I'm trying to pivot a table in Postgres. My table 'sample' has many columns (code, sector, item, year, period, value, preorder), instead of having 1 concept, 1 year, 1 value per row, i want the concept with values by year. From this;
Item Value Year PreOrder
Sales 50 2011 1
Costs -20 2011 2
GrossProfit 30 2011 3
Expenses -5 2011 4
Tax -3 2011 5
Profit 22 2011 6
Sales 45 2012 3
Costs -20 2012 4
GrossProfit 25 2012 5
Expenses -5 2012 6
Tax -3 2012 7
Profit 17 2012 8
To this:
Item 2011 2012
Sales 50 45
Costs -20 -20
GrossProfit 30 25
Expenses -5 -5
Tax -3 -3
Profit 22 17
Using crosstab in Postgres:
Select * from crosstab($$Select item, year, value from sec_sample
Where cik=320193
AND period='Annual'
AND Sector='Agro'
Order by year, preorder
$$,
$$VALUES ('2011'::int), ('2012')$$)
AS value("item" varchar(255), "2011" numeric(20,2), "2012" numeric(20,2));
However this results in:
Item 2011 2012
Sales 50
Costs -20
GrossProfit 30
Expenses -5
Tax -3
Profit 22
Sales 45
Costs -20
GrossProfit 25
Expenses -5
Tax -3
Profit 17
Any idea how i can modify my query? Thx
AFAIK, to group by item you have to order by item:
Select * from crosstab($$Select item, year, value from sec_sample
Where cik=320193
AND period='Annual'
AND Sector='Agro'
Order by item, year, preorder
$$,
$$VALUES ('2011'::int), ('2012')$$)
AS value("item" varchar(255), "2011" numeric(20,2), "2012" numeric(20,2));
But you can pivot without using crosstab, like this:
select
s.item,
sum(case when s.year = 2011 then s.value else 0 end) as "2011",
sum(case when s.year = 2012 then s.value else 0 end) as "2012"
from sec_sample as s
group by s.item
order by min(s.preorder)
I think it's easier to modify this type of query
sql fiddle demo