Showing posts with label qty. Show all posts
Showing posts with label qty. Show all posts

Thursday, February 16, 2012

Calculating Totals

Hi,
I have a query that shows an item that can have multiple rows of data
associated with it.
ITEM PRICE QTY_on_BO EXT PRICE PO No. QTY on PO
12345 36 3 108 2589
10
12345 36 3 108 8965
7
12345 36 3 108 4563
5
78945 20 5 100 1258
11
78945 20 5 100 9632
4
I am trying to total the QTY_on_BO column. The issue is that I only need to
sum (3+5 = 8) not (3+3+3+5+5 =19). Same thing with the column EXT_Price, I
only need to sum (108+100=208) not (108+108+108+100+100=524).
I would appreciate any help you could provide.
Thanks,
Kevin
P.S. here is my query:
SELECT va.item, i.description, v.vendor_name, va.buyer_code,
va.cost_amt, va.purchase_order, va.due_date, dbo.SKU.list_price_amt,
COALESCE
((SELECT SUM(order_qty -
original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
FROM dbo.ORDER_DETAIL AS od
WHERE (order_type IN ('E', 'P')) AND
(order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
(item_class NOT IN ('995', '998', '999'))
AND (item = va.item)),
0) AS BOQuantity, COALESCE
((SELECT SUM(order_qty -
original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
FROM dbo.ORDER_DETAIL AS od
WHERE (order_type IN ('E', 'P')) AND
(order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
(item_class NOT IN ('995', '998', '999'))
AND (item = va.item)),
0) * dbo.SKU.list_price_amt AS ext_bo_retail, va.qty AS PO_QTY
FROM dbo.VENDOR_ACTIVITY AS va INNER JOIN
dbo.ITEM AS i ON va.item = i.item INNER JOIN
dbo.VENDOR AS v ON va.vendor_key = v.vendor_key INNER
JOIN
dbo.SKU ON i.item = dbo.SKU.item CROSS JOIN
dbo.ORDER_DETAIL
WHERE (va.due_date > '2008-03-25')
GROUP BY va.item, i.description, va.buyer_code, va.cost_amt, va.due_date,
v.vendor_name, va.purchase_order, dbo.SKU.list_price_amt, va.qty
HAVING (COALESCE
((SELECT SUM(order_qty -
original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
FROM dbo.ORDER_DETAIL AS od
WHERE (order_type IN ('E', 'P')) AND
(order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
(item_class NOT IN ('995,''998', '999'))
AND (item = va.item)),
0) > 0)
ORDER BY COALESCE
((SELECT SUM(order_qty -
original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
FROM dbo.ORDER_DETAIL AS od
WHERE (order_type IN ('E', 'P')) AND
(order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
(item_class NOT IN ('995', '998', '999'))
AND (item = va.item)),
0) * dbo.SKU.list_price_amt DESC, va.due_dateI really could use some help with this.
Still trying to figure this out, but everytime I sum I get a sum of all the
contents of the cells instead of a sum of by item.
Please help if you can.
Thanks,
Kevin
"Kevin Eck" <keck@.titlenine.com> wrote in message
news:Olyzp$PkIHA.4120@.TK2MSFTNGP06.phx.gbl...
> Hi,
> I have a query that shows an item that can have multiple rows of data
> associated with it.
> ITEM PRICE QTY_on_BO EXT PRICE PO No. QTY on PO
> 12345 36 3 108
> 2589 10
> 12345 36 3 108
> 8965 7
> 12345 36 3 108
> 4563 5
> 78945 20 5 100
> 1258 11
> 78945 20 5 100
> 9632 4
> I am trying to total the QTY_on_BO column. The issue is that I only need
> to sum (3+5 = 8) not (3+3+3+5+5 =19). Same thing with the column
> EXT_Price, I only need to sum (108+100=208) not (108+108+108+100+100=524).
> I would appreciate any help you could provide.
> Thanks,
> Kevin
> P.S. here is my query:
> SELECT va.item, i.description, v.vendor_name, va.buyer_code,
> va.cost_amt, va.purchase_order, va.due_date, dbo.SKU.list_price_amt,
> COALESCE
> ((SELECT SUM(order_qty -
> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
> FROM dbo.ORDER_DETAIL AS od
> WHERE (order_type IN ('E', 'P')) AND
> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
> (item_class NOT IN ('995', '998', '999'))
> AND (item = va.item)),
> 0) AS BOQuantity, COALESCE
> ((SELECT SUM(order_qty -
> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
> FROM dbo.ORDER_DETAIL AS od
> WHERE (order_type IN ('E', 'P')) AND
> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
> (item_class NOT IN ('995', '998', '999'))
> AND (item = va.item)),
> 0) * dbo.SKU.list_price_amt AS ext_bo_retail, va.qty AS PO_QTY
> FROM dbo.VENDOR_ACTIVITY AS va INNER JOIN
> dbo.ITEM AS i ON va.item = i.item INNER JOIN
> dbo.VENDOR AS v ON va.vendor_key = v.vendor_key INNER
> JOIN
> dbo.SKU ON i.item = dbo.SKU.item CROSS JOIN
> dbo.ORDER_DETAIL
> WHERE (va.due_date > '2008-03-25')
> GROUP BY va.item, i.description, va.buyer_code, va.cost_amt, va.due_date,
> v.vendor_name, va.purchase_order, dbo.SKU.list_price_amt, va.qty
> HAVING (COALESCE
> ((SELECT SUM(order_qty -
> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
> FROM dbo.ORDER_DETAIL AS od
> WHERE (order_type IN ('E', 'P')) AND
> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
> (item_class NOT IN ('995,''998', '999'))
> AND (item = va.item)),
> 0) > 0)
> ORDER BY COALESCE
> ((SELECT SUM(order_qty -
> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
> FROM dbo.ORDER_DETAIL AS od
> WHERE (order_type IN ('E', 'P')) AND
> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
> (item_class NOT IN ('995', '998', '999'))
> AND (item = va.item)),
> 0) * dbo.SKU.list_price_amt DESC, va.due_date
>
>
>|||Hi Kevin,
I've had this problem in the past and even though I came up with a solution
it is not very elegent. My solution was, for each group (e.g. your ITEM
group), extend the SQL to include a count of the number items in the group
(e.g. join (select Item, count(*) from ... group by Item) t on ...). Then
this count value can be used to divide down the overall total to get the
correct result.
I would mind coming up with a more elegent solution that perhaps uses the
scope functions (Sum(value, scope), Count(value, scope)) but I haven't
figured that out yet.
Regards,
Brian
"Kevin Eck" <keck@.titlenine.com> wrote in message
news:%23PEwzTdkIHA.748@.TK2MSFTNGP04.phx.gbl...
>I really could use some help with this.
> Still trying to figure this out, but everytime I sum I get a sum of all
> the contents of the cells instead of a sum of by item.
> Please help if you can.
> Thanks,
> Kevin
> "Kevin Eck" <keck@.titlenine.com> wrote in message
> news:Olyzp$PkIHA.4120@.TK2MSFTNGP06.phx.gbl...
>> Hi,
>> I have a query that shows an item that can have multiple rows of data
>> associated with it.
>> ITEM PRICE QTY_on_BO EXT PRICE PO No. QTY on PO
>> 12345 36 3 108 2589 10
>> 12345 36 3 108 8965 7
>> 12345 36 3 108 4563 5
>> 78945 20 5 100 1258 11
>> 78945 20 5 100 9632 4
>> I am trying to total the QTY_on_BO column. The issue is that I only need
>> to sum (3+5 = 8) not (3+3+3+5+5 =19). Same thing with the column
>> EXT_Price, I only need to sum (108+100=208) not
>> (108+108+108+100+100=524).
>> I would appreciate any help you could provide.
>> Thanks,
>> Kevin
>> P.S. here is my query:
>> SELECT va.item, i.description, v.vendor_name, va.buyer_code,
>> va.cost_amt, va.purchase_order, va.due_date, dbo.SKU.list_price_amt,
>> COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) AS BOQuantity, COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) * dbo.SKU.list_price_amt AS ext_bo_retail, va.qty AS PO_QTY
>> FROM dbo.VENDOR_ACTIVITY AS va INNER JOIN
>> dbo.ITEM AS i ON va.item = i.item INNER JOIN
>> dbo.VENDOR AS v ON va.vendor_key = v.vendor_key
>> INNER JOIN
>> dbo.SKU ON i.item = dbo.SKU.item CROSS JOIN
>> dbo.ORDER_DETAIL
>> WHERE (va.due_date > '2008-03-25')
>> GROUP BY va.item, i.description, va.buyer_code, va.cost_amt, va.due_date,
>> v.vendor_name, va.purchase_order, dbo.SKU.list_price_amt, va.qty
>> HAVING (COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995,''998', '999'))
>> AND (item = va.item)),
>> 0) > 0)
>> ORDER BY COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) * dbo.SKU.list_price_amt DESC, va.due_date
>>
>>
>>
>|||Found a simple solution to this: divide the price or quantity by "count(*)
over(partition by item)"
"Brian" <brian1taylor@.hotmail.com> wrote in message
news:%23cJovqFoIHA.2632@.TK2MSFTNGP04.phx.gbl...
> Hi Kevin,
> I've had this problem in the past and even though I came up with a
> solution it is not very elegent. My solution was, for each group (e.g.
> your ITEM group), extend the SQL to include a count of the number items in
> the group (e.g. join (select Item, count(*) from ... group by Item) t on
> ...). Then this count value can be used to divide down the overall total
> to get the correct result.
> I would mind coming up with a more elegent solution that perhaps uses the
> scope functions (Sum(value, scope), Count(value, scope)) but I haven't
> figured that out yet.
> Regards,
> Brian
> "Kevin Eck" <keck@.titlenine.com> wrote in message
> news:%23PEwzTdkIHA.748@.TK2MSFTNGP04.phx.gbl...
>>I really could use some help with this.
>> Still trying to figure this out, but everytime I sum I get a sum of all
>> the contents of the cells instead of a sum of by item.
>> Please help if you can.
>> Thanks,
>> Kevin
>> "Kevin Eck" <keck@.titlenine.com> wrote in message
>> news:Olyzp$PkIHA.4120@.TK2MSFTNGP06.phx.gbl...
>> Hi,
>> I have a query that shows an item that can have multiple rows of data
>> associated with it.
>> ITEM PRICE QTY_on_BO EXT PRICE PO No. QTY on PO
>> 12345 36 3 108 2589 10
>> 12345 36 3 108 8965 7
>> 12345 36 3 108 4563 5
>> 78945 20 5 100 1258 11
>> 78945 20 5 100 9632 4
>> I am trying to total the QTY_on_BO column. The issue is that I only
>> need to sum (3+5 = 8) not (3+3+3+5+5 =19). Same thing with the column
>> EXT_Price, I only need to sum (108+100=208) not
>> (108+108+108+100+100=524).
>> I would appreciate any help you could provide.
>> Thanks,
>> Kevin
>> P.S. here is my query:
>> SELECT va.item, i.description, v.vendor_name, va.buyer_code,
>> va.cost_amt, va.purchase_order, va.due_date, dbo.SKU.list_price_amt,
>> COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) AS BOQuantity, COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) * dbo.SKU.list_price_amt AS ext_bo_retail, va.qty AS
>> PO_QTY
>> FROM dbo.VENDOR_ACTIVITY AS va INNER JOIN
>> dbo.ITEM AS i ON va.item = i.item INNER JOIN
>> dbo.VENDOR AS v ON va.vendor_key = v.vendor_key
>> INNER JOIN
>> dbo.SKU ON i.item = dbo.SKU.item CROSS JOIN
>> dbo.ORDER_DETAIL
>> WHERE (va.due_date > '2008-03-25')
>> GROUP BY va.item, i.description, va.buyer_code, va.cost_amt,
>> va.due_date, v.vendor_name, va.purchase_order, dbo.SKU.list_price_amt,
>> va.qty
>> HAVING (COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995,''998', '999'))
>> AND (item =>> va.item)), 0) > 0)
>> ORDER BY COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) * dbo.SKU.list_price_amt DESC, va.due_date
>>
>>
>>
>>
>

Sunday, February 12, 2012

Calculating a percentage using aggregate task

Hi,

I have a column called QTY and I need to calculate the percentage for each row based on the total sum of the column. They are all decimals. I have an OLE DB source that is reading the table used an aggregate task using the QTY column with operation SUM and called the output SUM OF QTY. Then I have a Derived Column task that takes the QTY column / SUM OF QTY * 100 to create the percentage. My numbers are not coming out correctly and when I put a data viewer from the aggregate task, it shows the same number for both columns:

QTY SUM OF QTY

0.01833 0.01833 (this should be the sum of all the decimals in the QTY col)

What am I doing wrong?

Thanks in advance!

Isabelle

You might have to use a multitask component to get this to work. The aggregate transformation does not pass fields through. So from the multitask output, you can take one path to the aggregate, and another to a sort. Take the output of the aggregate and put it in a sort as well. Then, take the two sorts and hook them up with a merge join on the common keys. Then, you'll have your original data, along with the aggregate column.|||

Thanks for your response. I tried what you suggested and I still could not get it to work. Even when I created a sort column for both and then used a join merge, I still got the same amound in both columns. I ended up doing the conversion using Execute SQL task and saved the output as a variable and then just called the variable in a derived column and that worked.

Isabelle

Calculating a percentage using aggregate task

Hi,

I have a column called QTY and I need to calculate the percentage for each row based on the total sum of the column. They are all decimals. I have an OLE DB source that is reading the table used an aggregate task using the QTY column with operation SUM and called the output SUM OF QTY. Then I have a Derived Column task that takes the QTY column / SUM OF QTY * 100 to create the percentage. My numbers are not coming out correctly and when I put a data viewer from the aggregate task, it shows the same number for both columns:

QTY SUM OF QTY

0.01833 0.01833 (this should be the sum of all the decimals in the QTY col)

What am I doing wrong?

Thanks in advance!

Isabelle

You might have to use a multitask component to get this to work. The aggregate transformation does not pass fields through. So from the multitask output, you can take one path to the aggregate, and another to a sort. Take the output of the aggregate and put it in a sort as well. Then, take the two sorts and hook them up with a merge join on the common keys. Then, you'll have your original data, along with the aggregate column.|||

Thanks for your response. I tried what you suggested and I still could not get it to work. Even when I created a sort column for both and then used a join merge, I still got the same amound in both columns. I ended up doing the conversion using Execute SQL task and saved the output as a variable and then just called the variable in a derived column and that worked.

Isabelle

Friday, February 10, 2012

Calculated Members Problem

1. I got the price and the qty in the data source. when I create the
calculated member Amount = Qty * price, I found out the total is equal to the
total qty * total price.
How can I define the calculated member Amount = summation of (qty *
price).
2. secondly, I would like to count how many order line. How can I do it in
the calculated members?
"Kam" <Kam@.discussions.microsoft.com> wrote in message
news:55973F33-03AE-481D-91BF-18C5C3FEB85F@.microsoft.com...
> 1. I got the price and the qty in the data source. when I create the
> calculated member Amount = Qty * price, I found out the total is equal to
the
> total qty * total price.
> How can I define the calculated member Amount = summation of (qty *
> price).
>
Define a measure with source column = Qty * price

> 2. secondly, I would like to count how many order line. How can I do it in
> the calculated members?
>
Try defining a mesaure on OrderID_OrderLineID with aggregate function
"Count". But it depends on the structure of the fact table
Francesco Anti
|||I defined Qty * price.
but my problem is the total sales = total qty * total price. It is wrong.
How can I define the total sales = total (qty * price)?
"Francesco Anti" wrote:

> "Kam" <Kam@.discussions.microsoft.com> wrote in message
> news:55973F33-03AE-481D-91BF-18C5C3FEB85F@.microsoft.com...
> the
> Define a measure with source column = Qty * price
> Try defining a mesaure on OrderID_OrderLineID with aggregate function
> "Count". But it depends on the structure of the fact table
> Francesco Anti
>
>

Calculated Members Problem

1. I got the price and the qty in the data source. when I create the
calculated member Amount = Qty * price, I found out the total is equal to th
e
total qty * total price.
How can I define the calculated member Amount = summation of (qty *
price).
2. secondly, I would like to count how many order line. How can I do it in
the calculated members?"Kam" <Kam@.discussions.microsoft.com> wrote in message
news:55973F33-03AE-481D-91BF-18C5C3FEB85F@.microsoft.com...
> 1. I got the price and the qty in the data source. when I create the
> calculated member Amount = Qty * price, I found out the total is equal to
the
> total qty * total price.
> How can I define the calculated member Amount = summation of (qty *
> price).
>
Define a measure with source column = Qty * price

> 2. secondly, I would like to count how many order line. How can I do it in
> the calculated members?
>
Try defining a mesaure on OrderID_OrderLineID with aggregate function
"Count". But it depends on the structure of the fact table
Francesco Anti|||I defined Qty * price.
but my problem is the total sales = total qty * total price. It is wrong.
How can I define the total sales = total (qty * price)?
"Francesco Anti" wrote:

> "Kam" <Kam@.discussions.microsoft.com> wrote in message
> news:55973F33-03AE-481D-91BF-18C5C3FEB85F@.microsoft.com...
> the
> Define a measure with source column = Qty * price
>
> Try defining a mesaure on OrderID_OrderLineID with aggregate function
> "Count". But it depends on the structure of the fact table
> Francesco Anti
>
>