Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Count of On Time or Late Orders when some orders lines are on time....and some are late

Hello  Community  -   Getting a distinct order count and basing it on if the order was on time or late is fairly straightforward...if you have one order number and one line  (or if multiple lines and all are on time...or all are late). 

 

But how to write a measure for this scenario where you have some order lines that are on time....and other lines on an order are late?  Our business logic is, if any Order line is late...the Order is defined as late.    And conceivably you could have an Order that appears multiple times, with a different due date than other order lines  (for example if the customer request some lines of the order to ship later, which happens in our business).    Here is a simple table example:  

 

Order #     Order Line              Due Date       Actual Ship Date

 

ABC-23         1                              JAN 4               JAN 5

ABC-23         2                              JAN 4               JAN 5

ACD-02        1                               FEB 12             FEB 12

ACD-02        2                               FEB 12             FEB 15 

AGH-09        1                               JAN 17            JAN 17

AGH-09        2                               JAN 17            JAN 21

AGH-09        3                               JAN 25            JAN 25

 

In the above scenarios, order ABC-23 is On Time.....all lines were on time.      ACD-02 would be considered Late because one of the lines shipped late.    AGH-09 would also be considered Late because one of the lines shipped late.  

 

So, on a table, I would want to see the following results: 

 

ABC-23    ON TIME 

ACD-02    LATE  

AGH-09    LATE 

 

 

      

 

 

 

1 ACCEPTED SOLUTION

Screenshot 2021-09-21 013844.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

Here are the steps you can follow:

1. Create calculated column.

Flag =
var _1=IF('Table'[Actual Ship Dat]>'Table'[Due Date],0,1)
return
SUMX(FILTER('Table','Table'[Order]=EARLIER('Table'[Order])),_1)

2. Create measure.

Result =
var _re=SUMX('Table','Table'[Flag])
return
IF(_re>0,"LATE","ON TIME"
)

3. Result:

vyangliumsft_0-1632370017106.png

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

CNENFRNL
Community Champion
Community Champion

Screenshot 2021-09-21 003940.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

Unfortunately this does not give the correct result.   I have a similar measure already that gives these same results.    What that "new status" column should really say is "Late" all the way down.   Because if even one line is late, the whole order needs to be classified as Late.   

 

texmexdragon_0-1632179866745.png

 

Screenshot 2021-09-21 013844.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.