MS Access 03 Query Criteras - ms-access-2003

If I have a report that tracks data for several accounts for each month with rows labeled:
UNITS,
REVENUE,
AVG REV/UNIT
How would I create a query that will filter the report to just show accounts where the UNITS row has increase/decreased 25% and the AVG REV/UNIT has increased/decreased 10%, from the previous month to the current month.
An example would be for the month of June I have the numbers....
JUN
UNITS 3,271
Revenue $3,598.10
Avg R/U $1.08
So when I run the report at the end of July I only want accounts that have a 25% difference in UNITS and/or a 10% difference in AVG REV/UNIT to show on a report.
qryPharmacy
SELECT PHAR_REPORT.*, (IIf(u1 Is Null,0,u1)+IIf(u2 Is Null,0,u2)+IIf(u3 Is Null,0,u3)+IIf(u4 Is Null,0,u4)+IIf(u5 Is Null,0,u5)+IIf(u6 Is Null,0,u6)+IIf(u7 Is Null,0,u7)+IIf(u8 Is Null,0,u8)+IIf(u9 Is Null,0,u9)+IIf(u10 Is Null,0,u10)+IIf(u11 Is Null,0,u11)+IIf(u12 Is Null,0,u12)) AS USUM, (IIf(r1 Is Null,0,r1)+IIf(r2 Is Null,0,r2)+IIf(r3 Is Null,0,r3)+IIf(r4 Is Null,0,r4)+IIf(r5 Is Null,0,r5)+IIf(r6 Is Null,0,r6)+IIf(r7 Is Null,0,r7)+IIf(r8 Is Null,0,r8)+IIf(r9 Is Null,0,r9)+IIf(r10 Is Null,0,r10)+IIf(r11 Is Null,0,r11)+IIf(r12 Is Null,0,r12)) AS RSUM, RMonth.*, PG2.*, PG.pGroup
FROM PHAR_REPORT, RMonth, PG2, PG
WHERE (((PHAR_REPORT.PR) Like ([PCODE] & '*')) And ((PG.pID)=PG2.PID))
ORDER BY PG2.pID, PHAR_REPORT.PR;

You should do it with more than one query. In the first query, select the data for the first month. On a second, to the desired month to compare. Create a third query that links the two first (be care about the correct relationship). Do the grouping/calculations in these queries.
In the 3rd query, create two fields that calculates increasing/decreasing for units and rev/unit. Now, you can add a criterium on each parameter field in the query columns.
The chalenge here is to be sure about hou would you work with the primary keys on months. Eg: if a A row in the first query isn't in the second (for not having an event on second month, for example), it will not be showed. In this case, the solution would be to create the queryes linking a table or query wich has the entyre set of registers, forcing it to show all the desired records despite they have or not occurrences.

Related

Tableau measure count items if between dates

What I am trying to achieve is to get a count of people employed in a particular period.
I have 3 variables:
Employee ID (integer)
Hire date (date)
Termination date (date or null)
Example
the formula I am looking for is something like
if termination_date is null
then
count employee_ID in
dates between Hire_date and max of either hire_date or termination_date
else
count employee ID in
dates between hire_date and termination_date
This aims to show the dynamic of staff level over the time.
I am new to Tableau, not sure how to even start with it. Any suggestions welcome.
This problem will be simpler if you reshape your data to have the following three columns
Employee ID
Date
Action. (where action takes on the values of ‘Hire’ or ‘Terminate’).
Each data row represents one change in status for an employees. If an employee had a termination date, they will have two records in this new format, otherwise just one record showing the hiring date.
You can reshape your data by hand, or leave the original and use Tableau Prep or the Tableau data source page to reshape using a self Union and a few simple calculated fields.
Define a calculated field called Staffing_Change as
if Action=‘Hire’ then 1 else -1 end
Now you can plot the change in staff level over time by putting exact date on columns and sum(Staffing_Change) on Rows. You can use a quick Table calc, Running Sum, to see the net staffing level. For line mark types, I’d use a step style by pressing on the path button on the Marks card. Otherwise, the chart can give the impression of fractional number of employees.

how to put condition users on tableau

im mysql user, i have data source like this
User_id | Order_id | Status_id | createdAt | Transaction_Amount
user_id as the user, order_id as the id of the order, status_id as the status of each order, createdAt as the date of the transaction .
in MySQL, i divide the condition of the users in 4 conditions.
conditions 1 new_user
the user who doing FIRST transaction in date range, and not doing transaction before the date range
conditions 2 repeat_user
the user who doing transaction before the end of date range, and doing atleast 1 more transactions in date range
conditions 3 existing_user
the user who doing his first transaction before the date range, and doing atleast 1 more transactions in date range
conditions 4 unique_user
the user who doing transaction in date range
i've done it with the queries in mysql, but i want to visualize it in tableau, i already make the filter of the time range, but how to make the conditions to based on condition user
Assuming that you want to have create these conditions in tableau, I propose a solution like this. Since you've not provided any data to work upon, a data I used in excel is as
View-1 add a Calculated field(CF) First Transaction of User as
{FIXED [user_id]: MIN([CreatedAt])}
Drag this field on filter instead of created at and you'll get a view based on your condition_1. Screenshot
View-2 (I am assuming that both transactions may have been completed within the filtered date range. If you need otherwise please specify).
step-1. drag user_id to rows, createdAt at filters (select range of dates).
Step-2 Drag order_id to filters again select count distinct, select at least 2
You'll get a view like this
View-3 Add two CFs as. 1st condition 1 as
Min([First Transaction of User])< min([CreatedAt])
another CF condition 3 check2 as
{Fixed [user_id]: COUNTD([order_id])}>1
Add both these CFs on filter shelf along with createdAt. Add condition-1 check2 to context (important step) select TRUE from both filters and you'll get desired view. like this
View-4 It is the most basic chart in tableau. Try and I am sure you can do it. Good luck
From your workbook it is clear that you want cohort analysis. In this regard Let me explain a few things..
First create a user cohort like this
{FIXED [user_id]: MIN([CreatedAt])}
Output of this field will be date when user first ordered. So if you will add this field to filters the output will be users (added in view) who first ordered within the filtered date/range.
Now if you want to see the users' orders during the same period (condition 1) also add the createdAt field to filters with same date/range.
E.g. suppose your date range is 5jan to 15 jan. Then set both filters to these dates range. First filter will ensure to filter customer with their first transaction and second one will give you desired output.
For condition2, you'll have to add countd(order_ids) to filters with filter value set 'at least 2'.
E.g. setting this filter will ensure that customer did their first and at least one more transaction during the date range.
For condition3, changing dates in filter accordingly will do. Nothing extra to be done.
E.g. suppose you want the customers with second and onward transaction between 5 jan to 15 jan. Then you will have to set first cohort filter with date upto 4 jan but second date filter to 5 jan to 15 jan
Condition 4: remove cohort from filters. Set date range on createdAt field only.
If you want to add another filters like status etc., These will work after you add them to filters.
Try this

Aggregate on day, month and week level

I am making a dashboard with clicks on a daily level and a month level on a certain campaign.
If I have say 1 customer clicking on 2 days then at a daily level that customer is counted twice. However, when I look at the aggregate monthly level this person will be counted once.
My SQL code that I am pulling into tableau is at a daily level. How do I get a monthly level view in the dashboard? When I am creating a parameter with month and day..on selecting month it is just adding the day level numbers to give me the month.
Any advice?
Sounds like a count distinct thing. To get around this the COUNTD would need to happen in Tableau. That would mean you need the Contact ID (or whatever it is you want to count) within the data source. Obviously that would mean your data source is much bigger but is the only way to get an accurate unique count over a custom time period.
Another alternative is to restrict the available time periods for the user and pre-aggregate for those time periods.

Crystal reports - Can't filter on custom formula number field

Crystal reports don't let me use a custom count formula field to filter which transactions to show in a manager report.
I'm creating a Crystal report that team leaders are supposed to take out to see on how many occasions their employees have reported in sick. A record is only supposed to show if that person has reported in sick 6 or more times the last 12 months.
The report shows a record (a page) for each employee belonging to the managers organisational unit. Below the employee information is a subreport where I show the transactions from the salary/time system. Using select expert, I have filtered out the transactions that is supposed to show. I have then created a database field that count which day was 12 months back from today, and filtered so that only the transactions falling into this period shows.
My last problem is that I only want to show the record that has a minimum of 6 such transactions during the period. I created a formula field named #Antal ("amount" in Swedish) that simply counts the distinct number of dates in the "from"-date for the salary transactions I'm showing (since a change of law 2019-01-01 we needed to create a new transaction type, so some of the occasions after 2019 may have two transactions referring to one sick leave, thus I'm counting the first day of the period instead), DistinctCount ({P_LSTAT.P_SXXX06})
Now, the subreport has a new column with Antal (amount) that counts the amount of the desired salary transaction. I then try to use the selection formula to only show records where {#Antal} >= 6 but I get the following error:
This formula cannot be used because it must be evaluated later
Is there any other (better) way of doing this, or am I simply missing something?
For your selection based on {#Antal} >= 6 you need to use the group selection formula, not the record selection formula. Record selection is used to select records which meet the criteria before reading in the data. Group selection is used to filter out entire groups of records based on summarised values, after the records have been read in and the summaries calculated - which sounds like exactly what you need here.
The value of a Formula Field is out of scope when the Select Expert is evaluated.
There is no process for calculating the value of a Formula Field before it is printed within the section of the report it is placed. The Select Expert is evaluated prior to any section of the report being printed, so at this time all Formula Fields are effectively Nothing.

Crystal Reports Sum per date from 2 different reports

I have spent several hours trying to google my issue with no luck. I was wondering if anyone here would know how to do this.
I have 2 separate unrelated tables:
The first table has bank deposits(all deposits for a specific day) with the amounts example:
1/4/16 $10
1/4/16 $20
1/5/16 $15
1/5/16 $25
The second table has transactions from my billing software example:
1/4/16 $5
1/4/16 $12
1/4/16 $17
1/5/16 $22
1/5/16 $2
1/5/16 $4
I need to create a report, so that I can pull the sum for each day-
1/4/16 - first table sum: $30 - second table sum: $34
1/5/16 - first table sum: $40 - second table sum: $28
Is this possible? If so, how can I do this. I can get the sums for each table separately by using a group on the specific date field but I can not figure out how to do them both at the same time.
I you don't want to do much on database then create two sub-reports
Group data on date for both reports(Suppress details and header if you don't need them).
In both report Place Group name then First/Second table sum then Grand total Summary for your amount field.
Place both reports in front of each other and align them base line.
This will hopefully work for you if min date in both tables is same.
If min date is different then you can create a view or stored procedure to join data and just group it on date.
You can link both the tables using joins on date column and just group by date and take summary in group footer
Edit.......
I assume your last record will be duplicated so use running total.
Create a new running total
First select the field to summarize.
Second evaluate select radio button on every record
Third reset...select on change of your calculated field.
Suppose if you are summarizing amount field then
Filed to summarize: select amount
Evaluate: select for every record
Reset: on change of field amount