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

Excluding data from calculation if it's not between two values (the previous and next row)

I'm trying to calculate average time remaining to the end of the work order for all steps and work orders in our database, specific to the part number. Essentially we're trying to see how long on average each step should take before work order completion (for each part number). We break down the work orders into steps and each step is supposed to go in sequence. We just discovered that sometimes Step 1 can be done in the middle of the work order, regardless of step order. I'd like to exclude these values from the overall average calculation.

 

This is what a "bad" work order looks like. Step 1 falls between step 20 and 21. I would like to exclude this value from the final calculation.

 

My thought process on how to do this is simple, but hard to put into DAX. I need something along the lines of: if the current line (step 1) is less than the previous line (step 20) and less than the next line (step 21) for a work order, exclude the current line (step 1) from the calculation.

 

I attempted to create an exact copy of the table in Power Query, then tried to use lookupvalue to obtain the previous and next step numbers on the same line as the current step. This would allow me to do the following check: If(Current Line<Previous Line && Current Line < Next Line, calculate the function, blank()). I just can't figure out how to pull the previous and next line into the current line to do this check before calculating averages.

 

This is a sample of my data which contains two work orders, one that's normal (steps in order) and one that we're trying to fix (steps not in order). I cannot post the Power BI file itself because it contains confidential information, but I've scrubbed these two example work orders. Any help would be greatly appreciated.

 

lkellner_1-1684247731416.png

 

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @Anonymous ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1684375943793.png

(2) We can create a calculated column and a table.

Column = 
var _a =CALCULATE(MAX('Table'[Step Rank]),FILTER('Table','Table'[WorkOrder Rank]=EARLIER('Table'[WorkOrder Rank])+1 && 'Table'[WorkOrder]=EARLIER('Table'[WorkOrder])))
var _b =CALCULATE(MAX('Table'[Step Rank]),FILTER('Table','Table'[WorkOrder Rank]=EARLIER('Table'[WorkOrder Rank])-1 && 'Table'[WorkOrder]=EARLIER('Table'[WorkOrder])))
return IF('Table'[Step Rank]<_a && 'Table'[Step Rank]<_b,1,0)
Table 2 = FILTER('Table','Table'[Column]=0)

(3) Then the result is as follows and you can then perform the calculations in Table 2.

vtangjiemsft_1-1684376017753.png

vtangjiemsft_2-1684376274506.png

 

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

View solution in original post

2 REPLIES 2
v-tangjie-msft
Community Support
Community Support

Hi @Anonymous ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1684375943793.png

(2) We can create a calculated column and a table.

Column = 
var _a =CALCULATE(MAX('Table'[Step Rank]),FILTER('Table','Table'[WorkOrder Rank]=EARLIER('Table'[WorkOrder Rank])+1 && 'Table'[WorkOrder]=EARLIER('Table'[WorkOrder])))
var _b =CALCULATE(MAX('Table'[Step Rank]),FILTER('Table','Table'[WorkOrder Rank]=EARLIER('Table'[WorkOrder Rank])-1 && 'Table'[WorkOrder]=EARLIER('Table'[WorkOrder])))
return IF('Table'[Step Rank]<_a && 'Table'[Step Rank]<_b,1,0)
Table 2 = FILTER('Table','Table'[Column]=0)

(3) Then the result is as follows and you can then perform the calculations in Table 2.

vtangjiemsft_1-1684376017753.png

vtangjiemsft_2-1684376274506.png

 

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Anonymous
Not applicable

My table did not upload when giving an example of a "bad" work order. Here's how the Step Rank looks and what we're trying to exclude:

 

lkellner_0-1684247937771.png

 

 

 

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.