How do I get an aggregate of aggregate on tableau? - aggregate

I have amount spent aggregated by 'account id' on different product 'categories':
Categories: A, B, C; Account IDs: 101, 102, 103..
101 A $12
101 B $13
101 C $11
102 A $11
102 B $13
103 A $15
103 C $11
I wish to have the average spend per user/account in Tableau:
101 $12
102 $12
103 $13
Thanks.

First account id needs to be dragged into dimension shelf.
To take the aggregate of price by account id. Just drag the account id and price to the rows shelf. Price will be summed up automatically. Double click the sum and change it into avg.

Related

Compare number of instances in a column for two different dates in SAS

I have the following dataset (items) with transactions on any date and amount paid on the next business day.
The amount paid for each id on the next business day is $10 for the ids whose rate is >5
My task is to compare the number of instances where rate > 5 are in line with amount paid on the next business day (This will have a standard code 121)
For instance, there are four instances with rate > 5 on 4/14/2017' - The amount$40 (4*10)is paid on4/17/2017`
Date id rate code batch
4/14/2017 1 12 100 A1
4/14/2017 1 2 101 A1
4/14/2017 1 13 101 A1
4/14/2017 1 10 100 A1
4/14/2017 1 10 100 A1
4/17/2017 1 40 121
4/20/2017 2 12 100 A1
4/20/2017 2 2 101 A1
4/20/2017 2 3 101 A1
4/20/2017 2 10 100 A1
4/20/2017 2 10 100 A1
4/21/2017 2 30 121
My code
proc sql;
create table items2 as select
count(id) as id_count,
(case when code='121' then rate/10 else 0 end) as rate_count
from items
group by date,id;
quit;
This has not yielded the desired result and the challenge I have here is to check the transaction dates (4/14/2017 and 4/20/2017) and next business day dates (4/17/2017,4/21/2017).
Appreciate your help.
LAG function will do the trick here. As we can use lagged values to create the condition we want without having to use the rate>5 condition.
Here is the solution:-
Data items;
set items;
Lag_dt=LAG(Date);
Lag_id=LAG(id);
Lag_rate=LAG(rate);
if ((id=lag_id) and (code=121) and (Date>lag_dt)) then rate_count=(rate/lag_rate);
else rate_count=0;
Drop lag_dt lag_id lag_rate;
run;
Hope this helps.

Tableau: How to perform "Summarize totals except top 3"?

I have data something like below for the name of person and the total sales he/she made:
ABC1 34
ABC2 45
ABC3 78
ABC4 79
ABC5 23
ABC6 61
ABC7 34
ABC8 54
ABC9 90
I have to display the dashboard as below, top 3 sales guys and the overall total sales made by rest of the team as ROT which is 498 - (90 + 78 + 79) = 251 team:
ABC9 90
ABC4 79
ABC3 78
ROT 251
For the top sales made, I gave a filter by sales person name, with Limit condition as "Top 3". But I am struggling to display the ROI even in a separate worksheet. Any help is appreciated.
Right click on your dimension [Sales Guy] and choose Create/Set
Define the set by the Top N (either hard code it or use a parameter to change it easily) and call it [TopNSalesGuy]
Create a calculated field [TopNSalesGuysPlusOther] with the formular:
IF [TopNSalesGuy] THEN [Sales Guy] ELSE 'ROT' END
Use [TopNSalesGuysPlusOther] in your table/graph and you should have the top N sales guys by name and everythign else as 'ROT

Merge Results in Crystal Reports

ID THINGS QTY PRICE
123 bag 1 25
123 shoes 1 10
123 pen 1 40
123 dress 1 20
The result in my report:
I put all the fields in sub_reports under group footer
bag 25x1 25
shoes 10x1 10
pen 40x1 40
dress 20x1 20
How can I merge them resulting to:
Materials 95x4 95
Can you help me.
As Siva suggested, you should probably have a Group created using your ID field, then Insert summary fields for sum(price) and sum(quantity) at the ID group. This will insert totals for both at the group footer

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?

How to sum multiple elements from single record

I have table trade:([]time:`time$(); sym:`symbol$(); price:`float$(); size:`long$())
with e.g. 1000 records, with e.g. 10 unique syms. I want to sum the first 4 prices for each sym.
My code looks like:
priceTable: select price by sym from trade;
amountTable: select count price by sym from trade;
amountTable: `sym`amount xcol amountTable;
resultTable: amountTable ij priceTable;
So my new table looks like: resultTable
sym | amount price
-------| --------------------------------------------------------------
instr0 | 106 179.2208 153.7646 155.2658 143.8163 107.9041 195.521 ..
The result of command: res: select sum price from resultTable where i = 1:
price
..
----------------------------------
14.71512 153.2244 154.1642 196.5744
Now, when I want to sum elements I receive: sum res
price| 14.71512 153.2244 154.1642 196.5744 170.6052 61.26522 45.70606
46.9057..
When I want to count elements in res: count res
1
I assume that res is a single record with many values, how can I sum all of those values, or how can I sum first for?
You can use "each" to run the sum on each row:
select sum each price from res
Or if you want to run on resoultTable:
select sum each price from resoultTable
To sum the first four prices for each row, use a dyadic each-right:
select sum each 4#/:price from resoultTable
Or you could do all of this very easily, in one step:
select COUNT:count i, SUM:sum price, SUM4:sum 4#price by sym from trade
q)trade:([]time:10?.z.d; sym:10#`a`b`c; price:100.+til 10; size:10+til 10)
One caveat with take (#) operator is, if the elements in the list are lesser than the take count , it treats the list as circular and start retruning the repetative results. E.g. check out the 4th price for symbol b and c.
q)select 4#price by sym from trade
sym| price
---| ---------------
a | 100 103 106 109
b | 101 104 107 101 //101 - 2 times
c | 102 105 108 102 //102 - 2 times
Using sublist can ensure that it the elemnts are lesser than passed count argument , it will just return the smaller list.
q)select sublist[4;price] by sym from trade
sym| price
---| ----------------
a | 100 103 106 109f
b | 101 104 107f
c | 102 105 108f