I have 2 fact tables, a sales transaction fact and and a Daily snapshot Fact. The purpose of the snapshot is to see which accounts were targeted for a specific promotion.
I am wanting to create a set to display the accounts that were targeted, but didn't have a transaction. Any help is appreciated.
This is what I attempted, but wasn't really close to getting it right. I don't want the set to display a measure, just the list of Accounts.
create set [targeted] AS
Distinct ([Account].[Account].[Account],[Measures].[SnapshotMeasure]);
create set [transacted] AS
Distinct ([Account].[Account].[Account],[Measures].[SalesMeasure]);
create set [targeted no sales] as
EXCEPT([targeted],[transacted] );
I'm assuming you want to add this to your cube script.
Maybe something like the following:
CREATE SET [NameOfYourCube].[targeted] AS
Filter([Account].[Account].[Account], [Measures].[SnapshotMeasure] > 0)
CREATE SET [NameOfYourCube].[transacted] AS
Filter([Account].[Account].[Account], [Measures].[SalesMeasure] > 0)
CREATE SET [NameOfYourCube].[targeted no sales] AS
EXCEPT([targeted],[transacted])
Related
I'm trying to think of the most straightforward way to store quantities of an item in a database. I'm creating a database to work in conjunction with a web app I'm developing to monitor and log gear lent out to people. So, I've thought a few different ways already, though I'm not sure if they will be easy to maintain into the future.
Idea 1
I have a gear table that stores the types of gear (e.g. shirt, pants, hat) along with data like sizes etc. Then for each time gear is taken out, it is logged in the gear_inventory table, storing details such as user id, gear type and boolean to signify if it was returned and return date. Then to track quantities, we'll have total_quantiy and count of gear out for a specific gear item in the gear table, this being updated manual with a second query triggered when an item is taken out or returned to plus or minus the given quantity.
Idea 2
Have the aforementioned total quantity out linked to the gear_inventory as a count of all non-returned items of that type.
Idea 3
Have an update task to change these quantities on table update or insert. Then do the same by adding or subtracting the quantity of a given query.
Idea 1 would be the easiest but not as reliable as the others. Idea 2 being the most reliable the handling of quantities is entering on the database to ensure. Then Idea 3 not as reliable since it's still relying on a scheduled task to update it.
So, how would you implement a quantity amount to ensure it doesn't get out of sync with the logged inventory records?
Edit 1
More info - The core solution I am trying to achive is having a method of storing or having a count of items taken out which can be compared to a total nunber associates with that item. As suggeated below, it will act in a similar fashsion to a bowling alley's loaning/borrowing shoes, exect users will be logged. So a record will be inserted when an item is borrrowed, and that record will be updated with return date on return. The types of items will be in its own table to store details on a general item, and that will have a one to many relationship with the logged gear table. The problem is, what is a full proof/reliable way to store/retrieve number of items out. Or am I overthinking this and a simple count query would sufice, not sure how intensive count is when performed oved and over again.
Let's think about what we're keeping track of.
Information about kinds of items.
Current inventory.
Which item?
How many?
What's been loaned out.
To whom?
Which items?
How many?
What's been returned.
By whom?
Which items?
How many?
First cut might look something like this:
create table items (
id serial,
name text,
...
);
create table inventory (
id serial,
item integer references items(id),
quantity integer check(quantity >= 0)
);
create table loans (
id serial,
user integer references users(id),
item integer references items(id),
quantity integer check(quantity >= 0),
when_loaned timestamp not null default now(),
when_returned timestamp
);
When you loan something out, insert a row into loans. When its returned, set loans.when_returned. If loans.when_returned is null, it's still out.
You could decrement the inventory when items are loaned, and increment it when they're returned. To preserve data integrity this should be done as a trigger, not as a scheduled process.
Alternatively, don't change the inventory quantities. Instead, subtract the number of loaned items from the amount in inventory. That's select sum(quantity) from loans where item = ? and when_returned is null from select quantity from inventory where item = ?. This makes loans and returns simpler, and avoids the possibility of the inventory count being corrupted, but it might cost performance problems if there's many, many outstanding loans.
What happens if you loan out 5 items and they return 3? How do you track that? One simple option is to split a single loan into two loans.
-- Copy the loan row
insert into loans
select * from loans where id = :orig_id
-- Track that 3 were returned
update loans
set quantity = 3, returned = now()
where id = :orig_id
-- Two are now outstanding
update loans
set quantity = 2
where id = :new_id
Without knowing more about what you're using this for, what the use cases are, and what the scale is, that's about all I can say. It's a good starting point.
I have an ODBC database that I've linked to an Access table. I've been using Access to generate some custom queries/reports.
However, this ODBC database changes frequently and I'm trying to discover where the discrepancy is coming from. (hundreds of thousands of records to go through, but I can easily filter it down into what I'm concerned about)
Right now I've been manually pulling the data each day, exporting to Excel, counting the totals for each category I want to track, and logging in another Excel file.
I'd rather automate this in Access if possible, but haven't been able to get my heard around it yet.
I've already linked the ODBC databases I'm concerned with, and can generate the query I want to generate.
What I'm struggling with is how to capture this daily and then log that total so I can trend it over a given time period.
If it the data was constant, this would be easy for me to understand/do. However, the data can change daily.
EX: This is a database of work orders. Work orders(which are basically my primary key) are assigned to different departments. A single work order can belong to many different departments and have multiple tasks/holds/actions tied to it.
Work Order 0237153-03 could be assigned to Department A today, but then could be reassigned to Department B tomorrow.
These work orders also have "ranking codes" such as Priority A, B, C. These too can be changed at any given time. Today Work Order 0237153-03 could be priority A, but tomorrow someone may decide that it should actually be Priority B.
This is why I want to capture all available data each day (The new work orders that have come in overnight, and all the old work orders that may have had changes made to them), count the totals of the different fields I'm concerned about, then log this data.
Then repeat this everyday.
the question you ask is very vague so here is a general answer.
You are counting the items you get from a database table.
It may be that you don't need to actually count them every day, but if the table in the database stores all the data for every day, you simply need to create a query to count the items that are in the table for every day that is stored in the table.
You are right that this would be best done in access.
You might not have the "log the counts in another table" though.
It seems you are quite new to access so you might benefit form these links videos numbered 61, 70 here and also video 7 here
These will help or buy a book / use web resources.
PART2.
If you have to bodge it because you can't get the ODBC database to use triggers/data macros to log a history you could store a history yourself like this.... BUT you have to do it EVERY day.
0 On day 1 take a full copy of the ODBC data as YOURTABLE. Add a field "dump Number" and set it all to 1.
1. Link to the ODBC data every day.
join from YOURTABLE to the ODBC table and find any records that have changed (ie test just the fields you want to monitor and if any of them have changed...).
Append these changed records to YOURTABLE with a new value for "dump number of 2" This MUST always increment!
You can now write SQL to get the most recent record for each primary key.
SELECT *
FROM Mytable
WHERE
(
SELECT PrimaryKeyFields, MAX(DumpNumber) AS MAXDumpNumber
FROM Mytable
GROUP BY PrimaryKeyFields
) AS T1
ON t1.PrimaryKeyFields = Mytable.PrimaryKeyFields
AND t1.MAXDumpNumber= Mytable.DumpNumber
You can compare the most recent records with any previous records.
ie to get the previous dump
Note that this will NOT work in the abvoe SQL (unless you always keep every record!)
AND t1.MAXDumpNumber-1 = Mytable.DumpNumber
Use something like this to get the previous row:
SELECT *
FROM Mytable
INNER JOIN
(
SELECT PrimaryKeyFields
, MAX(DumpNumber) AS MAXDumpNumber
FROM Mytable
INNER JOIN
(
SELECT PrimaryKeyFields
, MAX(DumpNumber) AS MAXDumpNumber
FROM Mytable
GROUP BY PrimaryKeyFields
) AS TabLatest
ON TabLatest.PrimaryKeyFields = Mytable.PrimaryKeyFields
AND
TabLatest.MAXDumpNumber <> Mytable.DumpNumber
-- Note that the <> is VERY important
GROUP BY PrimaryKeyFields
) AS T1
ON t1.PrimaryKeyFields = Mytable.PrimaryKeyFields
AND t1.MAXDumpNumber= Mytable.DumpNumber
Create 4 and 5 and MS Access named queries (or SS views) and then treate them like tables to do comparison.
Make sure you have indexes created on the PK fields and the DumpNumber and they shoudl be unique - this will speed things up....
Finish it in time for christmas... and flag this as an answer!
I am new to SQL and trying to learn by doing some beginner exercises. I'm working in Visual Studio.
I have one table with some Theater shows including Receipt ID, SeatRow and SeatNumbers.
I have another table consisting of Phone Numbers, Receipt IDs and TheatherShow IDs.
Now I want to make a third table showing how many seats are tied to each Receipt ID.
I've been trying to do this:
Update Table_Seat_Count
set Seat_Count = Count(Seat_Number) FROM Plads
WHERE ReceiptID = ReceiptID
Setting the Seat_Count equal to the number of seats where the ReceiptID is the same within the two tables.
Hope you can help me, thanks in advance.
You need a sub-select:
Update Table_Seat_Count
set Seat_Count = (select Count(Seat_Number) FROM Plads
WHERE Plads.ReceiptID = Table_Seat_Count.ReceiptID)
But in general it's a good idea to never store computed values. (If Plads is updated, and Table_Seat_Count isn't you've got inconsistent data...) Views are great, with them you'll always have consistent data!
I want to insert data from view to table by using Oracle Procedure.
The view is called VW_INVPART. The view consist of column from different tables:
(M_Product table)
AD_ORG_ID,
AD_Client_ID,
Name,
M_Product_ID,
(M_Storage table)
QtyOnHand,
(M_Replenish table)
level_min
(M_Product_PO table)
order_min
The table I want to insert is M_RequisitionLine.
My scenario is there's goods quantity which defined in QtyOnHand. QtyOnHand is dynamic so it can be changed depends on the logistic in-out process. then there's minimum level which is defined in level_min. When goods run out of stock, we can order it again and there's minimum order quantity which is defined in order_min.
So, when the amount of QtyOnHand is less than level_min, we can add data to column Qty in M_RequisitionLine in order to request stock. But there are minimum quantity to be put in M_RequisitionLine.Qty (order_min).
If level_min - QtyOnHand <= Order_min, then set M_RequisitionLine.Qty to Order_min.
But, If level_min - QtyOnHand >= Order_min, then set M_RequisitionLine.Qty into the difference between level_min and QtyOnHand.
How can I make the procedure in the Oracle? I've tried arranged the code but still confused as I am newbie in Oracle SQL.
You could write this into a PL/SQL stored procedure in the following way by using case command. Very basic example below. Keep in mind, I don't know what the entity relationships are for your tables or what their cadinality is, so a lot of what I did is based on singular value assumptions. If the select data returns more than one row, you have to use oracle collections.
Declare
t M_Storage.QtyOnHand%TYPE;
v M_Replenish.Level_min%TYPE;
o M_Product_PO.order_min%TYPE;
Begin
SELECT QtyOnHand INTO t FROM M_Storage;
SELECT Level_min INTO v FROM M_Replenish;
SELECT Order_min INTO o FROM M_Product_PO;
CASE
When t-v < o Then UPDATE M_RequisitionLine set qty = o;
When t-v >= o then UPDATE M_RequisitionLine set qty = t-v;
END CASE;
END;
/
This functionality already exists in standard Adempiere.
For a product, define the min, max & replenishment rules on the Replenish tab of the Product Window. On the Purchasing tab, of the same window, you can define, per Supplier the Minimum Order Qty.
Now, if you run the Replenishment Report under the Material Management menu, you can run the report and generate Purchase Orders to fulfill the replenishment based on the rules you defined and this will honour the minimum order quantity set on the Purchasing tab,
It's not a technical solution but it works.
Now if your needs were even more complex fulfilment method that the standard you could define a custom replenishment rule. This is a simple java class that must implement the Interface org.compiere.util.ReplenishInterface and requires that you implement one function... getQtyToOrder.
Once you have your class defined you specify this class on the Warehouse window.
Now, on the Product window->Replenish tab you can select Custom as the Replenish Type and this class will be used to calculate the quantity to replenish.
This approach would be better as it maintains your ability to use any supported database rather than just Oracle.
I'm new to filemaker - liking it, but taking a while to get used to it
I'm creating a solution where customers checkin with their ID card.
The first time they do this, I need to link their card to their user record.
I have a user table, and want to click a button on the layout for this table to set the ID of a card. The ID of the card is simply sitting in a different table.
So I just want to get the most recent row in the checkin table
take the cardid from there
update the current user's card field to that value
I'm using mysql as a backend for filemaker, to imporve syncability to the web etc.
I know who to do this with SQL - its
update users set cardid = (select cardid from checkins order by checkintime desc limit 1) where id = [current user id];
so I was thinking the executesql from filemaker would work, but I can't figure out how to pass in the [current user id]
I'm so close to getting this working I can taste it, but stumped!
Any hints would be appreciated. thanks.
OK I figured this out finally. Will put the answer here in case it helps someone.
Was simple, just need to use the Calculated SQL text option in the Execute SQL script step:
this is what worked
"update users set felicaid = (select felicaid from checkins order by checkintime desc limit 1) where id = " & users::id
Also needed a refresh window with flush SQL data option enabled step after that to update the UI