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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
WorkHard
Helper V
Helper V

Calculate First Occurence in a Column based on 2 criteria

I'm trying to calculate the First time the Event Expired based on the earliest Index.

 

|-Event-||-Index-||-Status-||-First Occurrence Expired-|
Event11Valid 
Event12Valid 
Event13ExpiredFirst
Event14Expired  
Event15Expired  
Event16Expired  
Event17Expired  
Event21ExpiredFirst
Event22Expired  
Event31Valid 
Event32ExpiredFirst
Event33Expired 
Event34Expired 

I'm almost there but I don't know where to take it from here:

 

First Occurrence Expired = CALCULATE(MAX(datasource[Index]),
FILTER(datasource,datasource[Event] = EARLIEST(datasource[Event]) &&
'datasource'[Index] = EARLIEST('datasource'[Index]) && 
datasource[Status] = "Expired"))

 

This gives me the correct index.

 

1 ACCEPTED SOLUTION
FrankAT
Community Champion
Community Champion

Hi @WorkHard ,

if I understood you right then this can be the solution:

 

14-05-_2021_22-59-23.png

 

First Occurance Expired = 
VAR _MinIndex = CALCULATE(MIN('Table'[Index]), FILTER(ALLEXCEPT('Table','Table'[Event]),'Table'[Status] = "Expired"))
RETURN
    IF(MIN('Table'[Index]) = _MinIndex , "First" , "")

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

View solution in original post

3 REPLIES 3
FrankAT
Community Champion
Community Champion

Hi @WorkHard ,

if I understood you right then this can be the solution:

 

14-05-_2021_22-59-23.png

 

First Occurance Expired = 
VAR _MinIndex = CALCULATE(MIN('Table'[Index]), FILTER(ALLEXCEPT('Table','Table'[Event]),'Table'[Status] = "Expired"))
RETURN
    IF(MIN('Table'[Index]) = _MinIndex , "First" , "")

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

super confused.

The RETURN of 

MIN('Table'[Index])

(last line in your code) is always returning 1 for me.

Fixed it by removing MIN from the calculation. It's possible that you were creating a measure and I am using a calculating column.

First Occurance Expired = 
VAR _MinIndex = CALCULATE(MIN('Table'[Index]), FILTER(ALLEXCEPT('Table','Table'[Event]),'Table'[Status] = "Expired"))
RETURN
    IF('Table'[Index] = _MinIndex , "First" , "")

 

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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