Create a column with daily number of orders in SSIS? - ssis

I'm trying to create a new column with the daily orders (the count of OrderNumber for each day). Since I have data coming from multiple sources, I'm using SSIS. My final table should look like this:
Date | Product Number | Quantity Sold | Number of Orders (for that date)
I've tried using Aggregate, but it's not working because of the other columns. I was thinking about creating a parallel source (the same staging table), on which I would use Aggregate to find the number of daily orders, and then find a way to bring it back to the final table, but there must be an easier way?

Aggregate transform takes and outputs only columns you select. So, for your case, select Date, Product, Quantity and some column for Order Count - we will return to this later. Specify Group by for the first two columns, Sum for the third, and Count for the forth. At output you will receive four columns with desired result.
Source column for Count should represent orders and does not include columns used in the first three functions. If you need to use one of these three columns, create a copy of it with Derived Column transfer. I would not recommend using (*) (all columns) for Count, since it will count rows with Null values as well.

Related

Single record of greatest n per group from a table with three identifiers

I have a table in which each record is a single purchase made by a single client.
Purchases can be made in different categories of product and different geographical areas (each of these is a single field).
I can count how many purchases each client has in each combination of product/area like this
Select client_id, product_id, zone_id, COUNT(purchase_id)
Group by client_id, product_id, zone_id
From this I would like to get a table where each record is the client, product and zone with the highest number of purchases. So only one row per client.
How would I go about doing this?
I think I might be able to do it by using NOT EXISTS where there is no record with the same three identifiers and higher COUNT, but as this is part of a much larger query I'm afraid of performance issues.
I also figure I might be able to concatenate the three identifiers into a single one, but I need those identifiers to be in separate fields as I need them for a join in another query this will be part of.
Step 1: Generate a temp table with the 3 columns plus count as you mentioned.
Step 2: Apply a groupwise-max algorithm. Either follow the link you have or check out Groupwise-Max

Plot total number of users by date joined

Is there any function or node which will add the number of elements in a set chronologically?
I would like to create a simple line graph of "total number of users" over time, but what I have is "user_email" (unique) and "date_created" for the date the user joined.
What is the easiest way to sum the number of users at any given time from their creation date and plot it in a graph according to time?
I tried searching for this, but didn't find anything related. New to KNIME. Thanks.
If you are sure that user_email only contains unique values, you can sort the table by date_created (if it isn't already sorted) then use a Counter Generation node to add a column containing a counter value.
For a more general solution, if you want to count the cumulative total of unique values in a table column, you can use this sequence:
GroupBy configured to group by the column whose unique values you want to count and to aggregate on the column you want to plot this against - for example, your timestamp column, probably with either the First or Last aggregation method
Sorter to sort on the aggregation column from GroupBy
then Moving Aggregation with the Cumulative computation box checked, and configured to aggregate on Count of the grouped column from GroupBy.

Totaling Records in MS Access

I have a query that returns the list of sales by customers, but I would like to know just the customer details and total value of sales. The only way I think of being able to do this is to create a second query based on the first one, remove the fields that cause unique records (e.g. description, goods) so I am only left with customer and sale value and then total/group that.
Is that the only way around or can this be done in one query.
Either this, or you can also copy your existing query, and do the grouping and summing in the copy.
But obviously you need two queries if you want both the full list and the totals query.
Edit: If you only need the totals, then edit the original query. Remove the columns you don't need, group by customer, sum the sale values.

where to find different types of items in a particular order_header_key IBM Sterling OMS

I am trying to write a query in STERLING database. I really wonder where to get the number of items ordered in a order.
I can get number of orders from yfs_order_header table but how to get how much quantity of of different items being ordered in each order.
For this you have yfs_order_line which is a hangoff enabled table and has the reference of yfs_order_header table. So there can be many order lines for a single order. So write a query to get the sum of order quantity from order lines table with order header as the condition. This will give you the number of quantities in an order if you group it with inventory_item_Id you ll get the no of quantities against each item.

Difficult MS Access Query - how to combine them?

I am trying to build an access report based on data from multiple different tables within the database.
I have 3 columns which perform calculations, and I am wondering how to put this query together. All 3 columns deal with dates, but calculate them differently.
The first column retrieves the most recent date of action for a userid if the type of action is "B":
select pid, Max(date) as most_recent
from actions
where ref = 'B'
group by pid;
The second column performs a calculation based on 2 fields, one is a date and one is a number in months. I am unsure how to add these two fields so that the number is added to the date as a number of months.
what i have so far is:
select nummonths,Max(lastvisit) from users
the third column I need to select the first date thats in the future for each user (next appointment date), there will be dates before and after this date so its a little difficult:
select uid,date from visits
The code for the last 2 queries needs to be slightly modified, and I was wondering what the best approach would be to join these all together? A type of join?
If you need to build a report with data from the 3 queries, you will need related data to join them. In that case, please send the structure of the tables.
If you need to show 3 lists in one report, you can use subreports: create a new empty report. In design mode, you can add 3 subreports from the toolbox bar. To each of the subreport assign the record source property to the corresponding sql.
regards
I am unsure how to add these two fields so that the number is added to the date as a number of months.
Use the DateAdd() function:
SELECT DateAdd("m", 2, LastVisit) FROM ...
Results in a date two months from the LastVisit date.