New to SSRS.
I have created some parameters. however...
I am trying to create a count parameter / filter for a report in report builder 3.0.
I have the view of customers orders
ID, OrderID, Department, Date, delivered, Cancelled
columns delivered and Cancelled, are represented by 1, or 0
I want to have a parameter that the user of the report can select, the number of times an ID cancels a orders.
this can be 1, 2,3 or even 4 times.
thus when a user selects e.g 4, it filters the table to IDs that have cancelled orders 4 times
I thought of creating a count, and group on the ID in the SQL view.
however I need the date of each of the orders in the view. to see what dates the cancellations was occurring. thus just getting 1 per row.
So I can't create a parameters based on distinct number of cancelations, I would just return 1
any ideas please
Thank you bjones, that outer apply worked (see comment)
Thank you x
thanks team
Related
I have a place_analytics table where I fetch followed places per month, my problem is that, when I fetch distinct count on monthly basis, it simply ignores the distinct value and fetched unwanted(described in screenshot) record based on monthly basis.
Note: A user can follow/unfollow same place multiple times, I do not delete this data but store with multiple entries.
For instance, in below screenshot, I have filtered the result based on place_id, where user_id=5 follows place_id=4 in May, unfollows it in July, then follows back also in July.
When I query,
SELECT place_id, COUNT(DISTINCT user_id) as follow_count
FROM place_analytics
WHERE is_followed=1
GROUP BY place_id
which is expected results, But, when I add another group by clause by months as,
MONTHNAME(STR_TO_DATE(MONTH(created_at), '%m'))
It returns, following result set where place_id 4 appears multiple times.
QUESTION
If user_id=5 has followed/unfollowed the place_id=4 in May, and followed in July. My query should only consider one record through out the table and ignore monthly group by. Is this possible?
Detail MySQL Fiddle is here,
Expected result should be,
I created a simple report that has 5 columns (CompanyName, Bought, Sold, Returned, Total)
This is what it looks like.
CompanyName Bought Sold Returned Total
With the exception of the Company Name, every value is a number. I created simple queries for Bought, Sold and Returned. For Total I used arithmetic in the main query (basically the sum of Bought, Sold, Returned (Returned is always negative)). The problem I came across is that for some companies, some of the columns (Bought,Sold,Returned) are NULL since ex: they don't have any RETURNED so when I run the report, it doesn't show me any value for TOTAL. Unless I have values in all three(BOUGHT SOLD and RETURNED) - nothing gets displayed in TOTAL. I don't want to display any zeros in the report itself because it would be too clustered, but is there a way for me to convert the NULL to 0 only when it does the calculation and but hide it from the report?
When trying to manipulate and display date from ONE table, I am having difficulty coding it correctly.
I need to, from the same table, find the amount of Services done per day (Which has been done, based on the Count of ServiceId). I then need to find the OverallCharge (done) and find the min, max and avg of these overallCharge (s) per day (BasicCharge + AdditionalPartsCharge + AdditionalLabourCharge)
I need to display these charges per ServiceDate in the table
My draft is the following but is telling me that ServiceId is not part of an aggregate function.
SELECT Service.ServiceDate, Service.NumServices , Min(OverallCharge) AS MinOverallCharge, Max(OverallCharge) AS MaxOverallCharge, Avg(OverallCharge) AS AverageOverallCharge
FROM (SELECT Service.ServiceId, Sum([BasicCharges]+[AdditionalLabourCharges]+[AdditionalPartCharges]) AS OverallCharge, Service.ServiceDate, Count (Service.ServiceId) AS NumServices
FROM Service
GROUP BY Service.ServiceDate, NumServices, MinOverallCharge, MaxOverallCharge, AvgerageOverallCharge);
Thanks
I'm looking to make some bar graphs to count item sales by day, month, and year. The problem that I'm encountering is that my simple MySQL queries only return counts where there are values to count. It doesn't magically fill in dates where dates don't exist and item sales=0. This is causing me problems when trying to populate a table, for example, because all weeks in a given year aren't represented, only the weeks where items were sold are represented.
My tables and fields are as follows:
items table: account_id and item_id
// table keeping track of owners' items
items_purchased table: purchaser_account_id, item_id, purchase_date
// table keeping track of purchases by other users
calendar table: datefield
//table with all the dates incremented every day for many years
here's the 1st query I was referring to above:
SELECT COUNT(*) as item_sales, DATE(purchase_date) as date
FROM items_purchased join items on items_purchased.item_id=items.item_id
where items.account_id=125
GROUP BY DATE(purchase_date)
I've read that I should join a calendar table with the tables where the counting takes place. I've done that but now I can't get the first query to play nice this 2nd query because the join in the first query eliminates dates from the query result where item sales are 0.
here's the 2nd query which needs to be merged with the 1st query somehow to produce the results i'm looking for:
SELECT calendar.datefield AS date, IFNULL(SUM(purchaseyesno),0) AS item_sales
FROM items_purchased join items on items_purchased.item_id=items.item_id
RIGHT JOIN calendar ON (DATE(items_purchased.purchase_date) = calendar.datefield)
WHERE (calendar.datefield BETWEEN (SELECT MIN(DATE(purchase_date))
FROM items_purchased) AND (SELECT MAX(DATE(purchase_date)) FROM items_purchased))
GROUP BY date
// this lists the sales/day
// to make it per week, change the group by to this: GROUP BY week(date)
The failure of this 2nd query is that it doesn't count item_sales by account_id (the person trying to sell the item to the purchaser_account_id users). The 1st query does but it doesn't have all dates where the item sales=0. So yeah, frustrating.
Here's how I'd like the resulting data to look (NOTE: these are what account_id=125 has sold, other people many have different numbers during this time frame):
2012-01-01 1
2012-01-08 1
2012-01-15 0
2012-01-22 2
2012-01-29 0
Here's what the 1st query current looks like:
2012-01-01 1
2012-01-08 1
2012-01-22 2
If someone could provide some advice on this I would be hugely grateful.
I'm not quite sure about the problem you're getting as I don't know the actual tables and data they contain that generates those results (that would help a lot!). However, let's try something. Use this condition:
where (items.account_id = 125 or items.account_id is null) and (other-conditions)
Your first query is perfectly acceptable. The fact is you don't have data in the mysql table and therefore it can't group any data together. This is fine. You can account for this in your code so that if the date does not exist, then obviously there's no data to graph. You can better account for this by ordering the date value so you can loop through it accordingly and look for missed days.
Also, to avoid doing the DATE() function, you can change the GROUP BY to GROUP BY date (because you have in your fields selected DATE(pruchase_date) as date)
I basically want to create a payment schedule in a separate table based on 4 values that a user would select. The payment schedule is very basic and the table only needs 2 columns, 1) Date of payment, 2) payment amount.
The 4 criteria values that are used to fill out this simple table would be: 1) the total amount of money, 2) number of payments, 3) the frequency of the payments (monthly, quarterly, semi-annually, annually), 4) the date of the first payment.
The way that I envision this is having a Form where these 4 values will be selected. On that form there can be a button to execute the command to fill in a datasheet with the appropriate values.
The first entry would obviously be on the date of the first payment, and the amount for that entry would be the total amount divided by the number of payments. For the second record dollar amount would be the same and the date would be the first payment date + the frequency. So if the first payment date is 1/1/2000 and the frequency annually, then the second entry date would be 1/1/2001. Etc.. until the last payment is made.
While it is a pretty simple payment schedule, I'm not sure how to best approach this in Access and if it's even possible. Would appreciate some input and direction. Thank you!
You will need
-- A numbers table with integers from 0 to the highest number of payments possible, indexed on the number.
-- A combobox called Frequency on forms payments with the following properties:
Row source: q;quarter;m;month;ww;week
Row source type : value list
Bound column : 1
Column count : 2
Column widths : 0, 1
-- A query
INSERT INTO Payments ( UserID, PaymentDate, Payment )
SELECT [Forms]![Payments]![UserID],
DateAdd([Forms]![Payments]![Frequency],
[Number],
[Forms]![Payments]![Startdate]) AS Expr2,
[Forms]![Payments]![LoanAmount]/
[Forms]![Payments]![NumberOfPayments] AS Expr3
FROM Numbers
WHERE (((Numbers.Number)<[Forms]![Payments]![NumberOfPayments]));
-- A button to run the query.