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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
ArT101
Helper I
Helper I

When Id has changed assign value 1

I've been trying to find either a Power Query code or DAX code that allows me to assign the value 1 when the ID within my column table has changed. So I have a table that has an ID column that has duplicated ID's and I want to create another column that holds the values of either 1 or 0 where 1 shows where in the row the ID has changed and 0 showing the duplicated ID's following after before the ID changes again. 

1 ACCEPTED SOLUTION
ArT101
Helper I
Helper I

2 REPLIES 2
ArT101
Helper I
Helper I

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Return-a-one-for-the-first-instance-of-duplic...

 

The following thread was a quicker method for me to apply which did the job.

Anonymous
Not applicable

Hi @ArT101 

Create a sample like this :

Ailsamsft_1-1670565478870.png

Then create a calculated column to group .

Group_Index = 
RANKX(FILTER(ALL('Table'),'Table'[GROUP]=EARLIER('Table'[GROUP])),[Index],,ASC)

You will get a result like this :

Ailsamsft_2-1670565623955.png

Finally , create a calculated column to compare the ID .

True = 
var _1=SUMX(FILTER(ALL('Table'),'Table'[GROUP]=EARLIER('Table'[GROUP])&&'Table'[Index]=EARLIER('Table'[Index])),[ID])
var _2=SUMX(FILTER(ALL('Table'),'Table'[GROUP]=EARLIER('Table'[GROUP])&&'Table'[Index]=EARLIER('Table'[Index])-1),[ID])
var _minindex=MINX(FILTER(ALL('Table'),'Table'[GROUP]=EARLIER('Table'[GROUP])),[Index])
return
IF([Index]=_minindex|| _1= _2,0,  SUMX(FILTER(ALL('Table'),'Table'[GROUP]=EARLIER('Table'[GROUP])&&'Table'[Index]=EARLIER('Table'[Index])-1),[Group_Index]))

The fianl result is like this :

Ailsamsft_3-1670565718238.png

Best Regards,
Community Support Team _ Ailsa Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.