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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
djdubbert
New Member

First Occurrence of a Value

I want to create a new column with a 1 when the 1st occurence of the 'Occurrences UID' column happens, and the new column to have a 0 for all other instances. In excel the formula is: =IF(COUNTIF($AO$2:AO2,AO2)>1,0,1). How could I accomplish this in Power BI? 

 

djdubbert_0-1626359953720.png

 

1 ACCEPTED SOLUTION
PaulOlding
Solution Sage
Solution Sage

How do you decide which is the first?  ie how is the list sorted?

In this example I'm sorting by a column called amt.  You can change that for however you want to sort it.  RANKX also has extra parameters for ordering ascending or descending if you need it.

 

First =
VAR _Current = 'Table'[Occurences UID]
VAR _Rank =
RANKX(
FILTER('Table',
'Table'[Occurences UID] = _Current
),
'Table'[amt]
)
VAR _Result = IF(_Rank = 1, 1, 0)
RETURN
_Result

View solution in original post

2 REPLIES 2
djdubbert
New Member

This worked! Thank you for your help!

PaulOlding
Solution Sage
Solution Sage

How do you decide which is the first?  ie how is the list sorted?

In this example I'm sorting by a column called amt.  You can change that for however you want to sort it.  RANKX also has extra parameters for ordering ascending or descending if you need it.

 

First =
VAR _Current = 'Table'[Occurences UID]
VAR _Rank =
RANKX(
FILTER('Table',
'Table'[Occurences UID] = _Current
),
'Table'[amt]
)
VAR _Result = IF(_Rank = 1, 1, 0)
RETURN
_Result

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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