Forum Discussion
Compare value with all previous rows
Hi!
I started working with Power BI and I have a task that I know that needs a calculated column, however I'm having some difficulties with it.
I need to compare the current cell of a column Sequence with all previous rows and write on the new calculated column "Ok" if it is the highest number so far, or "NOK" otherwise, as the example below.
| Seq. | ok/nok |
| 3280 | ok |
| 3281 | ok |
| 3282 | ok |
| 3284 | ok |
| 3283 | nok |
| 3285 | ok |
| 3286 | ok |
| 3287 | ok |
| 3288 | ok |
| 3289 | ok |
| 3268 | nok |
| 3274 | nok |
| 3290 | ok |
| 3291 | ok |
Hi Anonymous ,
At first, create an index column in the query editor.
Then you could create a column or a measure to get the result.
Column:
Column = VAR a = 'Table'[Index] VAR b = CALCULATE ( MAX ( 'Table'[Seq.] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Index] <= a ) ) RETURN IF ( b = 'Table'[Seq.], "OK", "NOK" )Measure:
Measure = VAR a = SELECTEDVALUE ( 'Table'[Index] ) VAR b = CALCULATE ( MAX ( 'Table'[Seq.] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Index] <= a ) ) RETURN IF ( b = SELECTEDVALUE ( 'Table'[Seq.] ), "OK", "NOK" )Here is the result.
Here is my test file for your reference.
2 Replies
- AnonymousNot applicable
HI Anonymous ,
Create an index Column from Power Query.
Then Create a Calculated Column
OKNOOK = var a = CALCULATE(MIN('Table'[Seq.]), FILTER('Table','Table'[Index] = EARLIER('Table'[Index])-1)) RETURN IF('Table'[Seq.] > a, "OK", "NOOK")
Regards,Harsh Nathani
Appreciate with a Kudos!! (Click the Thumbs Up Button)Did I answer your question? Mark my post as a solution!
- v-eachen-msftCommunity Support
Hi Anonymous ,
At first, create an index column in the query editor.
Then you could create a column or a measure to get the result.
Column:
Column = VAR a = 'Table'[Index] VAR b = CALCULATE ( MAX ( 'Table'[Seq.] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Index] <= a ) ) RETURN IF ( b = 'Table'[Seq.], "OK", "NOK" )Measure:
Measure = VAR a = SELECTEDVALUE ( 'Table'[Index] ) VAR b = CALCULATE ( MAX ( 'Table'[Seq.] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Index] <= a ) ) RETURN IF ( b = SELECTEDVALUE ( 'Table'[Seq.] ), "OK", "NOK" )Here is the result.
Here is my test file for your reference.