Forum Discussion

Tavi_'s avatar
Tavi_
Frequent Visitor
1 year ago
Solved

On Time total order level correct

 

See the picture above. How do I get the correct of amount of total orders on time (22% | 2 orders on time, total of 9 orders)?

 

Dump in Excel.

OrderOrder LineSales Order CountSales Order Count LinesSales Order Count Lines On TimeSales Order Lines On TimeSales Order On Time
00001149730000114973_00004011  0%
00001149730000114973_00005011  0%
00001158250000115825_00004011  0%
00001193600000119360_00006011  0%
00001205780000120578_00008011  0%
00001213040000121304_000080111100%100%
00001216740000121674_00005011  0%
00001216740000121674_00006011  0%
00001230460000123046_000020111100%100%
00001230460000123046_000030111100%100%
00001230460000123046_00007011  0%
00001230470000123047_000010111100%100%
00001230470000123047_00002011  0%
00001239080000123908_000050111100%100%

 

Currently I'm using this DAX formula

Sales Order On Time = IF([Sales Order Count] = 1, IF([Sales Order Count Lines] = [Sales Order Count Lines In Time], 1, 0), BLANK())



  • 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

3 Replies

  • 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))

     

     

     

    • Tavi_'s avatar
      Tavi_
      Frequent Visitor

      Thanks, it is not working in mine dataset yet. Could you explain your steps?

      • lbendlin's avatar
        lbendlin
        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