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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
davidtanchon
Frequent Visitor

How to get order for the last period

Hi, 

 

I would to write a formula that calculate the % order delay.

Each day we have a snapshot of open orders, and for each month I would like to calculate the % delay.

Meaning,  #of orders in delay/#of Orders

in delay = where Day GAP >0

#of Order = last order for each customer for the period (example here Order table id = 2,5,6

Meaning %delay will be 66% (2/3)

 

Order table idCustomerSnapshot DayDelivery dayOrder IDQtyDay GAP
1C101/01/202301/12/2022A131
2C102/01/202301/12/2022A232
3C201/01/202301/12/2022B131
4C202/01/202301/12/2022B132
5C203/01/202301/12/2022B133

6

C303/01/202331/03/2023C3-87

 

thanks for your help

10 REPLIES 10
johnt75
Super User
Super User

You could use

% order delay = VAR LastOrdersPerCustomer = INDEX(
	1,
	'Table',
	ORDERBY( 'Table'[Order table id], DESC),
	PARTITIONBY( 'Table'[Customer])
)
VAR NumWithDelay = COUNTROWS(
	FILTER( LastOrdersPerCustomer, 'Table'[Day GAP] > 0)
)
VAR Total = COUNTROWS( LastOrdersPerCustomer)
VAR Result = DIVIDE( NumWithDelay, Total)
RETURN Result

thanks, but it doesn't work. I have the following error message :

INDEX's Relation parameter may have duplicate rows. This is not allowed. 

Go into the Modelling view, select the Table and then set the order table id column as the key column. That should get rid of the error.

That's fixed the issue, but the result is wrong

davidtanchon_1-1689170265394.png

 

Couple of questions. What else is in the table or matrix visual? Anything that could be filtering the base table?

Is the order table ID column sorted in sequential order? If not, you may want to change the ORDERBY clause to use the snapshot day column instead.

Hi,

Thanks for your questions, here are the answers and sur-questions :

What else is in the table or matrix visual? Anything that could be filtering the base table?

==> What do you mean? this matrix is just an example, the right data model is stored in SSAS and it's a little bit more complex. I just wanted to have an example of a measure that I can adapte.

Is the order table ID column sorted in sequential order? 

==> no, it was an example, but in my model the Table ID is not sorted

If not, you may want to change the ORDERBY clause to use the snapshot day column instead.

==> I did it but it doesn't work.

 

Thanks

 

 

Not sure what the problem may be, the code worked with the sample data.

The underlying principal should work, you'll just need to adapt to fit your model. 

Use the INDEX function to get the latest row for each customer and you can then filter that for rows where Day Gap is not 0.

Just noticed that my code is checking for > 0, you may need to change that for <> 0.

Hi, Is it possible to get this column "Attended Value", meaning 1 in the last record for an Order Number.

knowing my report is based on SSAS cube

Entry DateDelivery DateOrder NumberDelay ValueLabel Range Order Delay MaxAttended Value
11/02/2023 00:0010/02/2023 00:00275741Retard de 1 à 10 jours20
12/02/2023 00:0010/02/2023 00:00275742Retard de 1 à 10 jours21
11/02/2023 00:0010/02/2023 00:00XH6651Retard de 1 à 10 jours180
12/02/2023 00:0010/02/2023 00:00XH6652Retard de 1 à 10 jours180
13/02/2023 00:0010/02/2023 00:00XH6653Retard de 1 à 10 jours180
14/02/2023 00:0010/02/2023 00:00XH6654Retard de 1 à 10 jours180
15/02/2023 00:0010/02/2023 00:00XH6655Retard de 1 à 10 jours180
16/02/2023 00:0010/02/2023 00:00XH6656Retard de 1 à 10 jours180
17/02/2023 00:0010/02/2023 00:00XH6657Retard de 1 à 10 jours180
18/02/2023 00:0010/02/2023 00:00XH6658Retard de 1 à 10 jours180
19/02/2023 00:0010/02/2023 00:00XH6659Retard de 1 à 10 jours180
20/02/2023 00:0010/02/2023 00:00XH66510Retard de 1 à 10 jours180
21/02/2023 00:0010/02/2023 00:00XH66511Retard de 11 à 20 jours180
22/02/2023 00:0010/02/2023 00:00XH66512Retard de 11 à 20 jours180
23/02/2023 00:0010/02/2023 00:00XH66513Retard de 11 à 20 jours180
24/02/2023 00:0010/02/2023 00:00XH66514Retard de 11 à 20 jours180
25/02/2023 00:0010/02/2023 00:00XH66515Retard de 11 à 20 jours180
26/02/2023 00:0010/02/2023 00:00XH66516Retard de 11 à 20 jours180
27/02/2023 00:0010/02/2023 00:00XH66517Retard de 11 à 20 jours180
28/02/2023 00:0010/02/2023 00:00XH66518Retard de 11 à 20 jours181

It looks like you could use

Attended value = INT( 'Table'[Max] = 'Table'[Delay value])

unfortunately, as my  report is based on SSAS model, INDEX function doesn't work.

I will post a new message with more details.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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