Forum Discussion
On Time total order level correct
- 1 year ago
Sales Order On Time =
VAR a =
ADDCOLUMNS (
VALUES ( 'Table'[Order] ), -- get distinct order numbers
"r", CALCULATE ( COUNTROWS ( 'Table' ) ), -- get number of line items per order
"o",
CALCULATE (
COUNTROWS ( 'Table' ),
'Table'[Sales Order Count Lines On Time] = 1 -- get number of line items per order that are on time
)
)
RETURN
COUNTROWS ( FILTER ( a, [r] = [o] && [o] > 0 ) ) -- count the number of orders where all line items are on time (the number of "on time" line items is not zero, and matches the number of total order line items
you are using a calculated column without aggregation. You probably want to use a measure instead.
Sales Order On Time =
var a = ADDCOLUMNS(VALUES('Table'[Order]),"r",calculate(COUNTROWS('Table')),"o",CALCULATE(COUNTROWS('Table'),'Table'[Sales Order Count Lines On Time]=1))
return countrows(filter(a,[r]=[o] && [o]>0))
Thanks, it is not working in mine dataset yet. Could you explain your steps?
- lbendlin1 year ago
Super User
Sales Order On Time =
VAR a =
ADDCOLUMNS (
VALUES ( 'Table'[Order] ), -- get distinct order numbers
"r", CALCULATE ( COUNTROWS ( 'Table' ) ), -- get number of line items per order
"o",
CALCULATE (
COUNTROWS ( 'Table' ),
'Table'[Sales Order Count Lines On Time] = 1 -- get number of line items per order that are on time
)
)
RETURN
COUNTROWS ( FILTER ( a, [r] = [o] && [o] > 0 ) ) -- count the number of orders where all line items are on time (the number of "on time" line items is not zero, and matches the number of total order line items