Ms Access 2007 - Can sort or group report but not both, can't figure out why - sorting

I'm stuck and confused and hopefully can get some help here. I have a query that pulls info from two tables and a report that reads it. My two tables are as such: One of the is a Contact list with phone numbers, names, and addresses. The other table is a paid history. The PhoneNumber field is how they're tied together. There are no duplicate entries in the Contact table but there are multiple paid instances per phone number in the other table.
My report groups them on the phone number, but I also need it to sort by date. My date field is marked as time/date, and it is in the paid table. The issue I'm running into is that I can either Group on PhoneNumber OR sort on the Date field but not both. When I set the Group as the top level, it ignores the Sort that I have set below it. If I take the sort and drag it up so that it becomes the top level, it won't group. When it doesn't group I'm left with multiple instances of the same Contact info... as in I get a new listing for every date that it has ever paid, whereas I need one a single Contact listing with each paid instance to be grouped underneath it.
Here's my query SQL:
SELECT
tblContributorsLead.FirstName,
tblContributorsLead.LastName,
tblContributorsLead.Address1,
tblContributorsLead.ZipCode,
tblContributorsLead.CityName,
tblPledgesLead.PledgeAmountRecd,
tblPledgesLead.DateRecd,
tblPledgesLead.PhoneNumber,
tblPledgesLead.DispositionTime,
tblPledgesLead.Agent,
tblPledgesLead.CampaignName,
tblPledgesLead.Custom20
FROM
tblContributorsLead
INNER JOIN
tblPledgesLead
ON tblContributorsLead.PhoneNumber = tblPledgesLead.PhoneNumber
WHERE
(((tblPledgesLead.PledgeAmountRecd)>0)
AND ((tblPledgesLead.DateRecd) Is Not Null));
Why would I only be able to either group OR sort but not both at the same time?
Edit: http://icloudbackups.com/stripped.zip is a copy of my database stripped down.

I think I understand now what you wanted - to have the phone number groups with the most recent dates show up at the top. To do this you need to identify the Last (or First if you need it the other way around) DateRecd for each PhoneNumber.
SELECT SortingAndGrouping.LastDate, SortingAndGrouping.PhoneNumber, tblPledgesLead.DateRecd
FROM (tblContributorsLead INNER JOIN tblPledgesLead ON
tblContributorsLead.PhoneNumber = tblPledgesLead.PhoneNumber) INNER JOIN
(SELECT CDate(Format(tblPledgesLead.DateRecd,"MM/DD/YYYY")) As LastDate, tblPledgesLead.PhoneNumber
FROM tblContributorsLead INNER JOIN tblPledgesLead ON
tblContributorsLead.PhoneNumber = tblPledgesLead.PhoneNumber
ORDER BY tblPledgesLead.DateRecd DESC) AS SortingAndGrouping ON
tblContributorsLead.PhoneNumber = SortingAndGrouping.PhoneNumber
ORDER BY SortingAndGrouping.LastDate DESC , SortingAndGrouping.PhoneNumber, tblPledgesLead.DateRecd DESC;
You will need to add the additional fields you want to display (I removed them here for clarity), and have the report enforce the same sorting I have here - Create a group for the LastDate column, then a group for the PhoneNumber column, then have the sorting specified.

Related

Unreliable results of a query

I need to get sales figures from open orders, sorted by code. The items are separated in the stock table by lot number (for traceability reasons) but the lot numbers do not appear in the orders table. The only link between the 2 tables is the part number.
When my query
SELECT code, SUM(qty*price) AS Sales
FROM orders INNER JOIN stock ON orders.partno = stock.partno
GROUP BY code
started returning strange results (very high sales figures for a given code), I changed it to
SELECT DISITNCT orders.partno, stock.lot, stock.code
FROM orders INNER JOIN stock ON orders.partno = stock.partno
and noticed that if several lots of a given part are in stock they are all returned
Part1 LotA code
Part1 LotB code
Part1 LotC code
which means that if a customer orders 300 units of Part1, my query returns 900 and my sales figure is multiplied by 3.
How can I work around that?
It must be noted that I do not work from a database but from a group of tables, the structures of which can sometimes be whimsical.
You should really use table.column or alias.column reference when writing queries. As your question stands, we do not know which table the PRICE comes from... the parts table or the lots table. If you are dealing with inventory tracking such as FIFO or LIFO method accounting, you must have an association to the lot table for inventory being tracked/sold.
Now, why are you getting large numbers? That is because of a Cartesian result. If you are not familiar with that, for each record in one table joined to another, it is returning however many matches.
So, if you have an order of one line item, there is only one line item in a products available table. So this is simple 1:1 ratio. Now, you have your STOCK table that can have multiple records for the exact same part number. You are now returning the same original order line item for EACH LOT ENTRY in the Stock table. So now, for your 1 item, you are getting 3 lots (1:3 result).
I know this is important from a cost-of-goods sold basis, hence your need to know which "lot" it is joined to so you only get that one specific record for proper pricing.
If however, you do have a generic product table of everything you sell, and that table has a generic common price no matter which "lot" was used for the sale, I would join to that table instead for your report. But you will still have the accounting issue of inventory, cost-of-goods, etc.

Crystal Reports group sorting

I have flight data records for each user. The table below shows an example for one user id. I need to group by user_id (show only one row for each user_id) that has the latest flight_date.
When I added grouping by user_id, the result report displays the right flight date, but the rest of the fields come from the last row for each user (highlighted fields).How do I make it show the entire row with the latest date (4th row in my example)? Thank you!
If you only want to see the most recent record, per userID, based on the flightdate, there are a few options. The most efficient way is to use a custom SQL command, but Crystal can do it by retrieving all of the records, and then suppressing the records you don't want to see.
1.Group the report by USERID (Report > Group Expert > Add the USERID field to the group section)
2. Sort the records by FlightDate ( Report > Sort Expert > Add FlightDate and select Descending NOTE: if FlightDate is not a date, we will need to create a formula to convert it into a date first, otherwise Crystal will treat it as a string and 12/2015 will be higher than 1/2016 (for example)
3.Create a running total to count the number of records within each group (This is how we will tell Crystal to suppress the records we don't want)
--Right click "running Total" on the right hand side, select New. Name it whatever you want; under Field To Summarize add FlightDate, change summary to COUNT
Leave Evaluate as "For Each Record"
Under Reset, select On Change of Group and select the group for USERID
The report should look like this
In the Section Expert, select Details and click the formula button next to "Suppress"
Enter the formula {#RecountCount} > 1 (Or whatever name your running total has)
Now you should only see one record for each user

OBIEE Merge two queries (join)

I need help.
I am new to obiee (recently moved from business objects and re-creating all reports in obiee).
Here is an example I need help with. I have created an analysis where I am listing all orders with their target delivery dates and number of products in each order.
Order Id......Target Delivery Date...No of products
Abc....1/1/2016.....5
I want to add to a column next to No of products called "No of prods delivered on time". I want to compare delivery date of each product within a order with the target delivery date and
Give count of products delivered within the target date.. So the output should be
Abc....1/1/2016....5.....3
Where 3 is number of products delivered on time.
I could do it in BO by running two queries and merging them however in obiee I am not able to add second query to my analysis. I did try at product level using case when target date >=delivery date then 1 else 0 and wrapped this with sum function to aggregate but it didn't work ..
Appreciate your help in this. Searching for this topics give me results for running queries from multiple subject area :(
You also have unions in OBIEE, you union the results of 2 queries which return the same structure, so you have query A with Order ID, Target Date, No Products and a Dummy column with a 0 and default agregation Sum, and a second query with Order ID, Target Date, Dummy column summing 0 and the number of products delivered.
You do all this in the criteria tab of the analysis. It's important the order in which you put your columns, because that's what OBIEE is using to do the union.
Regards

SSRS Tablix Cell Calculation based on RowGroup Value

I have looked through several of the posts on SSRS tablix expressions and I can't find the answer to my particular issue.
I have a dashboard I am creating that contains summary data for various managers. They are entering monthly summary data into a single table structured like this:
Create TABLE OperationMetrics
AS
Date date
Plant char(10)
Sales float
ReturnedProduct float
The data could use some grouping so I created a table for referencing which report group these metrics go into looks like this:
Create Table OperationsReport
as
ReportType varchar(50)
MetricType varchar(50)
In this table, 'Sales' and 'ReturnedProduct' are the Metric column, while 'ExecSummary' or 'Quality' are ReportType entries. To do the join, I decided to UNPIVOT the OperationMetrics table...
Select Date, Plant, Metric, MetricType
From (Select Date, Plant, Sales, ReturnedProduct From OperationMetrics)
UNPVIOT (Metric for MetricType in (Sales, ReturnedProduct) UnPvt
and join it to the OperationsReport table so I have grouped metrics.
Select Date, Plant, Metric, Rpt.MetricReport, MetricType
FROM OpMetrics_Unpivoted OpEx
INNER JOIN OperationsReport Rpt on OpEx.MetricType = Rpt.MetricType
(I understand that elements of this is not ideal but sometimes we are not in control of our destiny.)
This does not include the whole of the tables but you get the gist. So, they have a form they fill in the OperationMetrics table. I chose SSRS to display the output.
I created a tablix with the following configuration (I can't post images due to my rep...)
Date is the only column group, grouped on 'MMM-yy'
Parent Row Group is the ReportType
Child Row Group is the MetricType
Now, my problem is that some of the metrics are calculations of other metrics. For instance, 'Returned Product (% of Sales)' is not entered by the manager because it is assumed we can simply calculate that. It would be ReturnedProduct divided by Sales.
I attempted to calculate this by using a lookup function, as below:
Switch(Fields!FriendlyName.Value="Sales",SUM(Fields!Metric.Value),
Fields!FriendlyName.Value="ReturnedProduct",SUM(Fields!Metric.Value),
Fields!FriendlyName.Value="ReturnedProductPercent",Lookup("ReturnedProduct",
Fields!FriendlyName.Value,Fields!Metric.Value,"MetricDataSet")/
Lookup("Sales",Fields!FriendlyName.Value,Fields!Metric.Value,
"MetricDataSet"))
This works great! For the first month... but since Lookup looks for the first match, it just posts the same value for the rest of the months after.
I attempted to use this but it got me back to where I was at the beginning since the dataset does not have the value.
Any help with this would be well received. I would like to keep the rowgroup hierarchy.
It sounds like the LookUp is working for you but you just need to include the date to find the right month. LookUp will return the first match which is why it's only working on the first month.
What you can try is concatenating the Metric Name and Date fields in the LookUp.
Lookup("Sales" & CSTR(Fields!DATE.Value), Fields!FriendlyName.Value & CSTR(Fields!DATE.Value), Fields!Metric.Value, "MetricDataSet")
Let me know if I misunderstood the issue.

Access 2013: Check if a value is present in another table

I've just discovered Access, having always been an Excel/VBA man... and now I've hit a roadblock!
I'm building an inventory database for my employer. I have 2 tables, one containing one column of 'stockID's (lets call this table 'tblWarehouse'), and another containing two columns: a column of 'orderID's and a column of 'stockID's (lets call this table 'tblOrders'). (For the sake of this question, lets disregard things like quantity, price etc)
We don't keep all the goods we sell in our own warehouse, some are sourced directly from the manufacturer to the customer, which means that not all tblOrders!stockID will be present in the list tblWarehouse!stockID. I need to find out when this is the case!
I want to create a third column in tblOrders containing a dummy variable = 1 if that particular item is in our warehouse. In other words, I want to create a calculated column = 1 if tblOrders!stockID can be found in tblWarehouse!stockID. Can this be done?
I've found that I can't reference another table directly, so I've been trying my hand at queries, user defined functions and relationships, but to no avail. I've also been having trouble with the Access-lingo and veritable forest of different places to input seemingly the same expressions... so please, if u have an answer for me, be sure to specify where things are located!
Much obliged!!
If you are linking the two tables in a query using an inner join, only order records having at least one stock entry will be included in the result. In order to include those with no stock entry at all, create a left outer join.
SELECT O.OrderID, IIf(IsNull(MAX(W.StockID)), 0, 1) AS StockAvailable
FROM
tblOrder O
LEFT JOIN tblWarehouse W
ON O.StockID = W.StockID
GROUP BY O.OrderID
You can also determin the join type in the query designer by right clicking a relation line and selecting "Join Properties" and then select "Include ALL records from tblOrders ...". You can make a grouping query by clicking the big Sigma-symbol in the symbol list.

Resources