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
Shakerpowerbi
New Member

how do i get the previous id for each order ID

Hello luvs,

 

I’m trying to bullied a certain formula to help to get the previous order id, 

This must be done for each driver id and each day. 

 

the trick is for each driver id, the first order of the day must return the same id of that order, the second order of the day must return the first order id, third must return the second id ... etc. Until the all order of the same day are completed.

 

Please see below example, what i need to calculate is column (Previous order ID in same day) 

 

Shakerpowerbi_0-1671264074296.png

 

 

Thank you in advanced

 

1 ACCEPTED SOLUTION

Aha, it is easier in this case:

FreemanZ_1-1671278139507.png

View solution in original post

7 REPLIES 7
Shakerpowerbi
New Member

thank you, i've tried this with no luck , it did not result like i described above 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Data Table 
Order idDate of DeliveryDriver idOutput 
5345412/10/22 9:34 AM1153454
3453412/10/22 10:30 AM1153454
3534512/10/22 10:50 AM1134534
3534512/10/22 11:30 AM1135345
6546712/12/22 9:34 AM1165467
4574512/12/22 10:30 AM1165467
4574512/12/22 10:50 AM1145745
4574512/12/22 11:30 AM1145745
4745712/10/22 9:34 AM3347457
4577412/10/22 10:30 AM3347457
4754712/10/22 10:50 AM3345774
4575412/10/22 11:30 AM3347547
4564512/12/22 9:34 AM3345645
4564512/12/22 10:30 AM3345645
4564412/12/22 10:50 AM3345645
4645612/12/22 11:30 AM3345644

 

 

like above, i need to get the order id for the previues nearest delivered order by same driver on the same day

 

 

 

hi @Shakerpowerbi 

It would be easier with an Index Column. 

1) add an Index Column in Power Query

2) add a column with this:

Output2 = 
VAR _driverid = [DriverID]
VAR _date = INT([Date])
VAR _index =[Index]
VAR _dmin =
MINX(
    FILTER(
        tbl,
        _driverid = [DriverID]&&_date = INT([Date])
    ),
    tbl[Date]
)
VAR _OrderID =
MINX(
    FILTER(
        tbl,
        _driverid = [DriverID]&&_date = INT([Date])&&_index -1 =[Index]
    ),
    tbl[OrderID]
)
RETURN
IF(
    [Date] =_dmin,
    [OrderID],
    _OrderID
)

 

i tried and it worked like this:

FreemanZ_0-1671277959912.png

Data Table 
Order idDate of DeliveryDriver idOutput 
5345412/10/22 9:34 AM110
3453412/10/22 10:30 AM1153454
3534512/10/22 10:50 AM1134534
3534512/10/22 11:30 AM1135345
6546712/12/22 9:34 AM110
4574512/12/22 10:30 AM1165467
4574512/12/22 10:50 AM1145745
4574512/12/22 11:30 AM1145745
4745712/10/22 9:34 AM330
4577412/10/22 10:30 AM3347457
4754712/10/22 10:50 AM3345774
4575412/10/22 11:30 AM3347547
4564512/12/22 9:34 AM330
4564512/12/22 10:30 AM3345645
4564412/12/22 10:50 AM3345645
4645612/12/22 11:30 AM3345644

Aha, it is easier in this case:

FreemanZ_1-1671278139507.png

Mahesh0016
Super User
Super User

CALCULATE(SUM(Order[Driver Id]), OFFSET(-1,ALLSELECTED(Order[Date of Delivery]),ORDERBY(Order[Date of Delivery],ASC)))

 

Use Measure As a Don't summarize

 

Hello@Shakerpowerbi ,

i hope this post helps.

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

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.

Top Solution Authors