topic Measure with SUMMARIZE in Desktop
https://community.powerbi.com/t5/Desktop/Measure-with-SUMMARIZE/m-p/87581#M36710
<P> </P><P>I have a table with Sales data at the item level. The table has an OrderID column that contains the order number of the item so many items share the same OrderID. Also, an order can have items added and dropped from it over time.</P><P> </P><P>I need to have a calculated measure for the number of orders (distinct OrderID) that occured within a time period.</P><P> </P><P>I have a column, OrderCount, that contains 1 for the rows that represent a new order, a 0 for the rows that represent an order change, and -1 for the rows that represent a cancelled order.</P><P> </P><P>If I sum up the OrderCount column over time, for a specific OrderID, I will arrive at a number that is either positive, negative, or zero. A positive sum indicates 1 new order, a negative sum indicates 1 cancelled order, and a 0 indicates no new order or cancelled order. It doesn't really matter the size of the positive or negative number.</P><P> </P><P>This is what I thought I could do:</P><P> </P><P> </P><PRE>OrderCount =
CALCULATE (
SUM ( [WrittenOrders] ),
SUMMARIZE (
'Sales',
'Sales'[OrderID],
"WrittenOrders", IF (
SUM ( 'Sales'[OrderCount] ) > 0,
1,
IF ( SUM ( 'Sales'[OrderCount] ) < 0, -1, 0 )
)
)
)</PRE><P>I realize now that columns in the inner CALCULATETABLE function (the one I created called "WrittenOrders") aren't exposed to the outside CALCULATE context, so the SUM([WrittenOrders]) fails.</P><P> </P><P>How do I write this to do what I intend to do? I think I have my inner SUMMARIZE code written correctly to give me the sum by OrderID.</P><P> </P><P>Mike</P><P> </P><P> </P><P> </P>Tue, 08 Nov 2016 21:22:35 GMTxhead2016-11-08T21:22:35ZMeasure with SUMMARIZE
https://community.powerbi.com/t5/Desktop/Measure-with-SUMMARIZE/m-p/87581#M36710
<P> </P><P>I have a table with Sales data at the item level. The table has an OrderID column that contains the order number of the item so many items share the same OrderID. Also, an order can have items added and dropped from it over time.</P><P> </P><P>I need to have a calculated measure for the number of orders (distinct OrderID) that occured within a time period.</P><P> </P><P>I have a column, OrderCount, that contains 1 for the rows that represent a new order, a 0 for the rows that represent an order change, and -1 for the rows that represent a cancelled order.</P><P> </P><P>If I sum up the OrderCount column over time, for a specific OrderID, I will arrive at a number that is either positive, negative, or zero. A positive sum indicates 1 new order, a negative sum indicates 1 cancelled order, and a 0 indicates no new order or cancelled order. It doesn't really matter the size of the positive or negative number.</P><P> </P><P>This is what I thought I could do:</P><P> </P><P> </P><PRE>OrderCount =
CALCULATE (
SUM ( [WrittenOrders] ),
SUMMARIZE (
'Sales',
'Sales'[OrderID],
"WrittenOrders", IF (
SUM ( 'Sales'[OrderCount] ) > 0,
1,
IF ( SUM ( 'Sales'[OrderCount] ) < 0, -1, 0 )
)
)
)</PRE><P>I realize now that columns in the inner CALCULATETABLE function (the one I created called "WrittenOrders") aren't exposed to the outside CALCULATE context, so the SUM([WrittenOrders]) fails.</P><P> </P><P>How do I write this to do what I intend to do? I think I have my inner SUMMARIZE code written correctly to give me the sum by OrderID.</P><P> </P><P>Mike</P><P> </P><P> </P><P> </P>Tue, 08 Nov 2016 21:22:35 GMThttps://community.powerbi.com/t5/Desktop/Measure-with-SUMMARIZE/m-p/87581#M36710xhead2016-11-08T21:22:35ZRe: Measure with SUMMARIZE
https://community.powerbi.com/t5/Desktop/Measure-with-SUMMARIZE/m-p/87591#M36718
<P><LI-USER uid="7674"></LI-USER></P><P> </P><P>Hi Mike:</P><P> </P><P>Use this and let me know if solve your issue</P><P> </P><PRE>OrderTotal =
SUMX (
SUMMARIZE (
Table1,
Table1[OrderID],
"ORDERCOUNT", IF (
SUM ( Table1[OrderCount] ) > 0,
1,
IF ( SUM ( Table1[OrderCount] ) < 0, -1, 0 )
)
),
[ORDERCOUNT]
)</PRE>Tue, 08 Nov 2016 21:54:54 GMThttps://community.powerbi.com/t5/Desktop/Measure-with-SUMMARIZE/m-p/87591#M36718Vvelarde2016-11-08T21:54:54ZRe: Measure with SUMMARIZE
https://community.powerbi.com/t5/Desktop/Measure-with-SUMMARIZE/m-p/87602#M36727
<P>That's exactly what I needed.</P><P> </P><P>Thanks</P><P>Mike</P><P> </P>Tue, 08 Nov 2016 22:10:28 GMThttps://community.powerbi.com/t5/Desktop/Measure-with-SUMMARIZE/m-p/87602#M36727xhead2016-11-08T22:10:28Z