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
mahra-in
Helper II
Helper II

Same Day Delivery Status

Hi

 

Below is the sample of table I have

 

OrderLinePromised DateActual DateDiff DaysStatus
1234112-Feb-2108-Feb-21-4Ontime
1234212-Feb-2115-Feb-213Delay
1234315-Feb-2111-Feb-21-4Ontime
1234412-Feb-2113-Feb-211Delay
3322101-Feb-2102-Jan-21-30Ontime

 

In the above table, there are 2 Unique Orders.

 

If we consider Order 1234, Line 1  & 2 has same Promised Date which will be treated as single delivery and if one of the Line in a particular order with same Promised date has status as "Delay" then that single delivery (both Line 1 & 2) will be treated as 1 Delay.

And Line 3 in order 1234 is another delivery which has Ontime and Line 4 is another delivery which has Delay.

 

Line 1 & 2 as 1 Delivery, Line 3 as 1 Delivery & Line 4 as 1 Delivery - Total 3 Deliveries. 

 

Out of the Total 3 Deliveries,

Line 1 & 2 together treated as Delay since if atleast 1 or all has Delay status

Line 3 is Ontime

Line 4 is Delay

So only 1 Ontime

 

End Result for Order 1234 is 1/3 = 33% is the expected result. This is only for Order 1234

 

If I consider all the lines in table, there are 4 deliveries, out of which 2 is Ontime. 

So the End Result I want is 2/4 = 50%.

 

Can you please help to calculate this in Power BI

 

1 ACCEPTED SOLUTION

Hi  @mahra-in ,

 

First create an index column;

Then create 3 calculated columns as below:

_is ontime = 
var _previous =CALCULATE(MAX('Table'[Index]),FILTER('Table','Table'[Order]=EARLIER('Table'[Order])&&'Table'[Promised Date]=EARLIER('Table'[Promised Date])&&'Table'[Index]<EARLIER('Table'[Index])))
Return
IF(_previous<>BLANK(),BLANK(), CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Order]=EARLIER('Table'[Order])&&'Table'[Promised Date]=EARLIER('Table'[Promised Date])&&'Table'[Status]="Ontime")))
_is delay = 
var _previous =CALCULATE(MAX('Table'[Index]),FILTER('Table','Table'[Order]=EARLIER('Table'[Order])&&'Table'[Promised Date]=EARLIER('Table'[Promised Date])&&'Table'[Index]<EARLIER('Table'[Index])))
Return
IF(_previous<>BLANK(),BLANK(), CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Order]=EARLIER('Table'[Order])&&'Table'[Promised Date]=EARLIER('Table'[Promised Date])&&'Table'[Status]="Delay")))
exclusion = IF('Table'[_is delay]=BLANK(),0,ABS('Table'[_is delay]-'Table'[_is ontime]))

 Then create 2 measures as below:

Measure for order = 
var _numerator= CALCULATE(SUM('Table'[_is ontime])-SUM('Table'[exclusion]),FILTER(ALL('Table'),'Table'[Order]=MAX('Table'[Order])))
var _denominator=CALCULATE(SUM('Table'[_is ontime])+SUM('Table'[_is delay])-SUM('Table'[exclusion]),FILTER(ALL('Table'),'Table'[Order]=MAX('Table'[Order])))
Return
DIVIDE(_numerator,_denominator)
Measure for total = 
var _numerator= CALCULATE(SUM('Table'[_is ontime])-SUM('Table'[exclusion]),ALL('Table'))
var _denominator=CALCULATE(SUM('Table'[_is ontime])+SUM('Table'[_is delay])-SUM('Table'[exclusion]),ALL('Table'))
Return
DIVIDE(_numerator,_denominator)

And you will see:

v-kelly-msft_0-1614042753999.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

3 REPLIES 3
mahra-in
Helper II
Helper II

Yes this is only part of my data. If other rows have same delievry date & same order number then it will be considered as one delivery

Hi  @mahra-in ,

 

First create an index column;

Then create 3 calculated columns as below:

_is ontime = 
var _previous =CALCULATE(MAX('Table'[Index]),FILTER('Table','Table'[Order]=EARLIER('Table'[Order])&&'Table'[Promised Date]=EARLIER('Table'[Promised Date])&&'Table'[Index]<EARLIER('Table'[Index])))
Return
IF(_previous<>BLANK(),BLANK(), CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Order]=EARLIER('Table'[Order])&&'Table'[Promised Date]=EARLIER('Table'[Promised Date])&&'Table'[Status]="Ontime")))
_is delay = 
var _previous =CALCULATE(MAX('Table'[Index]),FILTER('Table','Table'[Order]=EARLIER('Table'[Order])&&'Table'[Promised Date]=EARLIER('Table'[Promised Date])&&'Table'[Index]<EARLIER('Table'[Index])))
Return
IF(_previous<>BLANK(),BLANK(), CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Order]=EARLIER('Table'[Order])&&'Table'[Promised Date]=EARLIER('Table'[Promised Date])&&'Table'[Status]="Delay")))
exclusion = IF('Table'[_is delay]=BLANK(),0,ABS('Table'[_is delay]-'Table'[_is ontime]))

 Then create 2 measures as below:

Measure for order = 
var _numerator= CALCULATE(SUM('Table'[_is ontime])-SUM('Table'[exclusion]),FILTER(ALL('Table'),'Table'[Order]=MAX('Table'[Order])))
var _denominator=CALCULATE(SUM('Table'[_is ontime])+SUM('Table'[_is delay])-SUM('Table'[exclusion]),FILTER(ALL('Table'),'Table'[Order]=MAX('Table'[Order])))
Return
DIVIDE(_numerator,_denominator)
Measure for total = 
var _numerator= CALCULATE(SUM('Table'[_is ontime])-SUM('Table'[exclusion]),ALL('Table'))
var _denominator=CALCULATE(SUM('Table'[_is ontime])+SUM('Table'[_is delay])-SUM('Table'[exclusion]),ALL('Table'))
Return
DIVIDE(_numerator,_denominator)

And you will see:

v-kelly-msft_0-1614042753999.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

v-kelly-msft
Community Support
Community Support

Hi @mahra-in ,

 

Is it part of your data or all of data?If other rows have the same delivery date and same order number,will them be considered as one delivery either?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

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.