PowerPivot: Add one product to another - powerpivot

We are combining products, and want to get an idea of what demand may look like for the combined products vs what we had before. Here is some sample data:
A mapping of where products will be going called SKU_Mapping:
Old Product | New Product
1 | 2
3 | 4
Then I have some historical sales information called Sales:
Product | Quantity
1 | 5
2 | 10
3 | 3
4 | 7
I also have a table with all the SKUs to link my two other tables together called Master_SKU
Product
1
2
3
4
I have relationships between 'Master_SKU'[Product] to 'Sales'[Product] and from 'Master_SKU'[Product] to 'SKU_Mapping[Old Product]
I am trying to get an output like this
New Product | Old Product | Original Quantity | New Quantity
2 | 1 | 10 | 15
4 | 3 | 7 | 10
I cannot figure out how to write a formula that says, take the quantity of the new product and add it to the quantity of the old product. I have tried a bunch of different operators but for the life of me I cannot figure it out. Any insights or suggestions will be appreciated. Thank you.

I did this:
Here's how:
I set up three tables exactly as you described, with the relationships as you described. Then I opened the SKU_Mapping table and I added a column:
Old Product Qty = CALCULATE(sumx(Sales,Sales[Quantity]),filter(Sales,Sales[Product]=SKU_Mapping[Old Product]))
...and another column:
New Product Qty = CALCULATE(sumx(Sales,Sales[Quantity]),filter(Sales,Sales[Product]=SKU_Mapping[New Product]))
...and one last column:
Total Qty = SKU_Mapping[Old Product Qty]+SKU_Mapping[New Product Qty]

Related

Database Design: Inventory with multilevel packaging

I'm trying to develop a database for my inventory. But I have no idea how to keep track of multilevel packaging.
For example:
I currently have a products and positions table
products
Id | Name
================
1013 | Metal
1014 | Wood
positions
id | Name
================
1 | 1-1-1-1
2 | 1-1-1-2
And my inventory table I was thinking of doing something like this:
Let's say I stored 1 box with 1000 Metal and 1 box with 500 Wood at position 1-1-1-1
ItemId | ProductId | Quantity | PositionId
==========================================
1 | 1013 | 1000 | 1
2 | 1014 | 500 | 1
So I'll label those two boxes with a barcode 1 and 2 respectively, so if I scan them, I can check this table to see the product and quantity inside them.
But I can also put these 2 boxes (1 and 2) inside another box (let's call it box 3), which would generate a new barcode for it that, if scanned, will show both previous boxes and its items. And store this box 3 in another position
And I can also put this box 3 inside a pallet, generating a new code and so on. So basically I can multilevel package N times.
What is the best table structure to keep track of all of this? Thanks in advance for any help!
I would add another column to the products table, make it a BIT and maybe call it BOM, BillOfMaterials, or whatever makes sense to you
So your products Table would look like this
Then you could create another table called BillOfMaterials
Quantity is how many of your products are needed to make up your new product. So for this example 2 metal and 1 wood make a pencil.
I was able to make a good structure:
My products and positions are the same but I created a stock table like:
id | product_id | amount | parent_id | position_id
=====================================================
1 | 1013 | 1000 | 4 | 1
2 | 1013 | 1000 | 4 | 1
3 | 1014 | 500 | 4 | 1
4 | 1234 | NULL | NULL | 1
The 1234 (random id) is a box that contains 2000 metal and 500 wood. I dont save this box in the product table.
When I scan the box with id 3, I perform a recursive cte query:
with recursive bom as (
select *, 1 as level
from testing.stock
where id = '4' #scanned id
union all
select c.*, p.level + 1
from testing.stock c
join bom p on c.parent_id = p.id
)
select product_id as product, sum(amount), position_id
from bom b
left join testing.product pd on b.product_id = pd.id
where pd.id is not null
group by product_id, position_id
which returns:
sum | product | position
2000 | 1013 | 3
500 | 1014 | 3
to get by position I just run a variation of the above query. To perform an update I get the Ids inside that box and run a
update testing.stock set position = '2' where id in (#variation of above query)
I hope this helps someone. This works for N packaging level

Trying to find non-duplicate entries in mostly identical tables(access)

I have 2 different databases. They track different things about inventory. in essence they share 3 common fields. Location, item number and quantity. I've extracted these into 2 tables, with only those fields. Every time I find an answer, it doesn't get all the test cases, just some of the fields.
Items can be in multiple locations, and as a turn each location can have multiple items. The primary key would be location and item number.
I need to flag when an entry doesn't match all three fields.
I've only been able to find queries that match an ID or so, or who's queries are beyond my comprehension. in the below, I'd need a query that would show that rows 1,2, and 5 had issues. I'd run it on each table and have to verify it with a physical inventory.
Please refrain from commenting on it being silly having information in 2 different databases, All I get in response it to deal with it =P
Table A
Location ItemNum | QTY
-------------------------
1a1a | as1001 | 5
1a1b | as1003 | 10
1a1b | as1004 | 2
1a1c | as1005 | 15
1a1d | as1005 | 15
Table B
Location ItemNum | QTY
-------------------------
1a1a | as1001 | 10
1a1d | as1003 | 10
1a1b | as1004 | 2
1a1c | as1005 | 15
1a1e | as1005 | 15
This article seemed to do what I wanted but I couldn't get it to work.
To find entries in Table A that don't have an exactly matching entry in Table B:
select A.*
from A
left join B on A.location = B.location and A.ItemNum = B.ItemNum and A.qty = B.qty
where B.location Is Null
Just swap all the A's and B's to get the list of entries in B with no matching entry in A.

Database design for products with multiple units

I am designing a database for retail business using Sql server as backend. There are some products that can be sold in multiple units, for example, pencils can be sold in ea and dozen, paper can be sold in sheet, ream, and canton. Basically, each product can be sold in more than one unit.
The App needs to supports
Can receive products from suppliers in many unit. Sometime we might
order 1 pencil and the next time we order 2 boxes of pencil.
Can sell products in multiple unit, for example, we must be able to
sell 1 box and 2 pencils in the same bill.
App also need supports for FIFO or LIFO
Below is my initial design
Table: Products
ProductId | Barcode | Name | BaseUnitId
1 | XXXX | Pencil | 1
Table: Units
UnitId | Name
1 | Each / Pieces
2 | Box
Table: UnitConversion
ProductId | BaseUnitId | Multiplier | ToUnitId |
1 | 1 | 24 | 2 | // 24 pencils in a box
Table: Inventories
Id | ProductId | UnitId | Quantity
1 | 1 | 1 | 48 //In pieces
Table Invoices
Id | ProductId | UnitId | Quantity
1 | 1 | 2 | 1.5 //Sold/Purchased 1.5 boxes that means 18 pieces
Is there any flaws in my design? Is there anything that I miss? This can't be a new problem. Does anyone have any ideas (or examples)?
I have a few suggestions:
It seems like you could remove the UnitConversion table and just store the Multiplier value against the Unit record (so you'd store 1 against Each / Pieces and 24 against Box). Then the conversion would just be the 'From' unit's quantity divided by the 'To' unit's quantity.
Is is possible that different units would have different barcodes? If so, the barcode could be stored against the Unit record instead.
In your Inventories and Invoices tables, the ProductId column might be unnecessary as you could get this by joining Units table.
To support FIFO or LIFO, you're going to need to store more specific information about your stock, so there's some way of knowing the date it was booked in, the quantity remaining, and maybe some way of identifying that specific item (or group of items).
Hope this helps!
EDIT: Your Inventories table could look something like this:
Id | UnitId | [identifier] | CurrentQuantity | DateAdded
1 | 1 | ABC123 | 20 | 2017-01-10
2 | 1 | ABC124 | 96 | 2017-01-12
The [identifier] column (name's up to you!) would store some way of identifying the physical stock, this could be something that the users assign on receipt of the item, or maybe their suppliers would already have added some that could be used.
To implement FIFO in a scenario where someone wants to buy 24 pencils, you know you need to take 20 from the group of items labelled 'ABC123' and 4 labelled 'ABC124'.

SQL find all orders but delete cancellations related to upgrade orders

Really difficult problem at the moment, as this is something that I am trying to do in SQL but I know should be done with another language such as PHP.
Essentially what I have is a database which has order numbers, and product codes related to policies.
For some orders there are multiple phases such as a cancellation, and an upgrade (for example when an upgrade is made the original policy is cancelled and then an upgrade is made for the difference)
What I want to do, is run a query that will exclude all cancellations related to an upgrade order (dictated as UP in product code) but keep all cancellations related to a change of detail (dictated as CD in product code).
So in short;
The query will need to find all orders including cancellations, but then delete any cancellation which has the same order number as a UP.
I know that this essentially could be done with a 'foreach' which finds all UP product codes, and the related order number, and then deletes all cancellations associated with that order number - but I don't know how to achieve this in SQL without creating multiple tables on a temporary basis and deleting them after.
Table Structure is as such:
| Order Number | Product Code | Transaction Value |
| 1 | RRCN | -30 |
| 1 | RRUP | 12 |
| 2 | SMFP | 30 |
| 3 | SMCN | -12 |
| 3 | SMCD | 12 |
| 4 | HUCN | -30 |
So I would need the query to show all the table, but remove the RRCN related to the RRUP. So query should look for RRUP, see it is order 1, then find the RRCN related to order 1 and remove this from the results - please note, results NOT the original table.
Any ideas? Much appreciated! (I am running SQL Server 2008)
This query should do the job:
SELECT * FROM Q19427600
WHERE RIGHT(ProductCode,2) <> 'CN'
OR (RIGHT(ProductCode,2) = 'CN' AND
OrderNumber NOT IN (SELECT OrderNumber FROM Q19427600 WHERE RIGHT(ProductCode,2) = 'UP'));
Returns results:
OrderNumber ProductCode TransactionValue
1 RRUP 12
2 SMFP 30
3 SMCN -12
3 SMCD 12
4 HUCN -30

MySQL query for initial filling of order column

Sorry for vague question title.
I've got a table containing huge list of, say, products, belonging to different categories. There's a foreign key column indicating which category that particular product belongs to. I.e. in "bananas" row category might be 3 which indicates "fruits".
Now I added additional column "order" which is for display order within that particular category. I need to do initial ordering. Since the list is big, I dont wanna change every row by hand. Is it possible to do with one or two queries? I dont care what initial order is as long as it starts with 1 and goes up.
I cant do something like SET order = id because id counts from 1 up regardless of product category and order must start anew from 1 up for every different category.
Example of what I need to achieve:
ID | product | category | Order
1 | bananas | fruits | 1
2 | chair | furniture | 1
3 | apples | fruits | 2
4 | cola | drinks | 1
5 | mango | fruits | 3
6 | pepsi | drinks | 2
(category is actually a number because it's foreign key, in example I put names just for clarification)
As you see, order numbers start anew from 1 for each different category.
Sounds like something a SQL procedure would be handy for.
Why not just set the order to the category? That is, why not:
update Table
set SortOrder = Category;
As an aside, you cannot have a column named order -- that is a reserved word in SQL.