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

Find first occurence of value according to date and string

Hello datanauts,

 

In PBI (example in the table below), I need to get the column "VeryFirstTestOkay", which gives out boolean values according to multiple filtering conditions.

 

The column "VeryFirstTestOkay" shall only return 1 if:

  1. all rows have been ordered by "Timestamp" ascending &&
  2. "Text" contains "0 Errors" &&
  3. "Text" hasn't been "0 Errors" || ">0 Errors" before

In humane words: I have to find out, if an article has gone through a test without errors at the first time or not.

 

ArticleTimestampTextVeryFirstTestOkayWhy "FirstTestOkay" has it's value
A04.08.2020 10:27System Start00 - because "Text" doesn't contain ">0 Errors"
A04.08.2020 10:29Resistance Test00 - because "Text" doesn't contain ">0 Errors"
A04.08.2020 10:300 Errors11 - because "Text" does contain ">0 Errors"
B04.08.2020 10:35System Start00 - because "Text" doesn't contain ">0 Errors"
B04.08.2020 10:36Failure00 - because "Text" doesn't contain ">0 Errors"
C04.08.2020 10:40System Start00 - because "Text" doesn't contain ">0 Errors"
C04.08.2020 10:41Resistance Test00 - because "Text" doesn't contain ">0 Errors"
C04.08.2020 10:431 Error00 - because "Text" does contain ">0 Errors"
C04.08.2020 10:44System Start00 - because "Text" doesn't contain ">0 Errors"
C04.08.2020 10:460 Errors11 - because "Text" does contain ">0 Errors" and article hasn't been tested before.
A05.08.2020 15:11System Start00 - because "Text" doesn't contain ">0 Errors"
A05.08.2020 15:121 Error00 - because "Text" doesn't contain ">0 Errors" & "VeryFirstTestOkay" has already been set to 1 for this article
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous - So basically this is Lookup Min/Max https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434

 

VeryFirstTestOkay = 
  VAR __Min = MINX(FILTER('Table',[Text] = "0 Errors" && [Article] = EARLIER('Table'[Article])),[Timestamp]
RETURN
  IF([Timestamp] = __Min && [Text] = "0 Errors",1,0)

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

@Anonymous - So basically this is Lookup Min/Max https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434

 

VeryFirstTestOkay = 
  VAR __Min = MINX(FILTER('Table',[Text] = "0 Errors" && [Article] = EARLIER('Table'[Article])),[Timestamp]
RETURN
  IF([Timestamp] = __Min && [Text] = "0 Errors",1,0)

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.