LOD Workaround with Tableau 8.3 - tableau-api

I'm new to Tableau. I have a customer-event table to show which customers attended which events (like webinars, etc). One of fields is sales - which is the sales for that customer 30 days from the date of the event.
custid eventid eventdt 30daysales
1 aa jan 1 $100
1 ab jan 1 $100
2 aa jan 2 $150
Note that customer 1 attended 2 events on the same day. So the sales number is duplicated. If I were building a report for a single event, it's no problem. But when I build a monthly report, I want sum(Sales) = $250 and not $350.
My report sample:
Month eventcount customercount 30daysales
Jan 2 2 $250
With tableau 9, I read that using an LOD formula would allow me to sum sales on a per customer basis. But I'm on Tableau 8.3 and I'm wondering what the manual workaround is.
How do I write the calculated field to compute the 30daysales without duplicating?

Related

Inventory transaction sum for each month

i have a table with detail transaction for lot. Lot are harvest and store before being ship.
Date lot transaction qty
5 sept 3 store 300
8 sept 3 ship -50
10 oct 3 ship -20
15 nov 3 ship -20
...
If i want the inventory for a specific moment, i simply sum between to date
I would like a query that can give me a sum from store to a specific month throught the entirr year like:
Lot sept to oct to nov ...
3 250 230 210 ...
Select lot, sum(qty) from ... where (date > 1 sept and date < 1 oct) as sept, (date > 1 sept and date < 1 nov)... group by lot
I did'nt find anything or figure out how to do it i a simple query.
Regards
Obtain one table with a query where is see the evolution of quantity over the year.

How to group previously-denormalized-data from a row

I have a table containing courses run by teachers, I want to grab the number of taught days and split these by years and teachers' status.
The table contains the following fields:
id teacher_id course_name course_date course_duration teacher_status
--------------------------------------------------------------------------
1 Teacher_01 Course_AA 2012-02-01 2 volunteer
2 Teacher_02 Course_BB 2012-02-01 7 employee
3 Teacher_03 Course_BB 2013-02-01 7 contractor
4 Teacher_01 Course_AA 2014-02-01 2 paid volunteer
5 Teacher_04 Course_AA 2014-06-01 2 paid volunteer
Teachers may run a course under various statuses: volunteer, paid volunteer, contractor, employee, etc. The status of a given teacher can change through time. The duration of a course is expressed in days.
I can already gather the sum of taught days by teachers, split by status. This is done by
SELECT
teacher_status,
sum(course_duration) AS "Taught days"
FROM
my_table
GROUP BY
teacher_status
;
But data is not normalized and different families of statuses have been mixed. So I want to gather the same info (number of taught days) split:
by 3 statuses: volunteer, paid volunteer, all other statuses,
and by years.
What is expected is:
Year Teacher_status Taught_days
---------------------------------------
2012 volunteer 2
2012 employee 7
2013 contractor 7
2014 paid volunteer 4
I've tried various combinations of aggregate functions, GROUP BY / HAVING / ROLLUP statements but without success. How should I achieve this?
You'll want to select a complex expression and then GROUP BY that, not just by a raw column value. You could either repeat the expression or, in Postgres, also refer to the column alias:
SELECT
EXTRACT(year FROM course_date) as year,
(CASE teacher_status
WHEN 'volunteer' THEN 'volunteer'
WHEN 'paid volunteer' THEN 'paid'
ELSE 'other'
END) AS status,
SUM(course_duration) AS "Taught days"
FROM
my_table
GROUP BY
year,
status;
To get your example result, I have this query
SELECT extract (year from course_date),
teacher_status,
sum(course_duration) AS "Taught days"
FROM
my_table
GROUP BY
extract (year from course_date),
teacher_status;

Month to date aggreate KPI query postgresql

I'm trying to find a way to obtain the amount of sales made from month to month but only comparing the aggregate total up to the current month's date.
In other words, I want to compare this month's sales up until now, against other months sales up until that month's same day.
Example using today's date as a reference (2016-06-18):
Total sales on January 2016 (*From 2016-01-01 to 2016-01-31*): 1000
Total sales on January 2016 (*From 2016-01-01 to 2016-01-17*): 650
Total sales on February 2016 (*From 2016-02-01 to 2016-01-17*): 670
Total sales on July 2016 (*From 2016-06-01 to current_date - 1*): 680
The structure of my data is as follows:
date sales
2016-01-01 5
2016-01-02 4
2016-01-03 5
2016-01-04 7
.
.
.
When I run the query I would like to have a monthly comparison of the totals mentioned above, so a result that looks like this:
month sales
2016-01 650
2016-02 670
.
.
2016-06 680
So comparing the month-to-date total of each month.
This is what I have tried so far and it seems to be fine, but somehow I always get a small difference whenever I make tests for limit days like the first of each month or the last.
select
order_month,
sum(sales) as sales
from table
where extract (day from order_date::date)
<=
extract (day from current_date::date)
- case when extract (day from current_date::date)=1 then 0 else 1 end
group by 1;

crystal reports formula's on group

crystal report grouped by company and invoiced
company name invoiceNo which has max(dayslate)? (maxdaysLate)
------------- records -------------------------------
there is a chance of one invoice is assigned to multiple companies,
for example
company1 inv1 30 days late (max(dayslate) col below)
invoiceNo duedate dayslate (cal field today - duedate)
inv1 2016-01-01 30
inv2 2016-01-01 30
Company2 inv3 26 days late(inv1 below has max but already in comp1, so 2nd max)
invoiceNo duedate dayslate
inv1 2016-01-01 30
inv3 2016-01-04 26
need help how to write a formula for max days late record field in a group (ex: inv1)
how to calculate max days as already one is used find second so on...
edit
days late is column which is calculated column (today - due date)
on group want to display which has max days late of that group and its related invoice number
there is chance of one invoice has been assigned to multiple companies, in case any that invoice has max days in 2 groups it should be calculated to only one company group and on other group it should consider the second highest

Crystal Reports Conditional Grouping on Unrelated DB Field

I have some data in table SSTemp like this ("..." indicates data omitted for readability):
Month Year Number Gross Net
1 2013 1 1,000 500
2 2013 1 1,000 500
...
12 2013 1 1,000 500
1 2014 1 1,000 500
2 2014 1 1,000 500
...
12 2014 1 1,000 500
1 2015 1 1,000 500
...
12 2015 1 1,000 500
I am new to Crystal Reports and am using version 8 (no, we can't upgrade). I want to roll up the totals for all line items in years past and leave the data as-is for the current year in the same report. Database field {CONTROLFILE.CURRENTYEAR} contains the current bookkeeping year for our system which is vital to determine the rollup groups. The CONTROLFILE table contains general settings for the system and has no data in it useful for JOINing, however I need to consider CURRENTYEAR for the grouping. The MONTH column should be blank on the summary lines, and indicate month on the current year lines. The end result data should look like this:
Month Year Number Gross Net
2013 12 12,000 6,000
2014 12 12,000 6,000
1 2015 1 1,000 500
2 2015 1 1,000 500
...
12 2015 1 1,000 500
Any suggestions would be most appreciated!
Use sub report concept.
In main report calculate for previous years in sub report calculate for current year.
In main report group by year And suppress details show summary in group footer in another group footer section place sub report and just place data in detail part don't group