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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

create new column based on two cells from different with same value

Hey there, 

I have following situation which I couldn't resolve yet:

I want to compare each row with the previous row.

 

If Colour and Previous Colour are both the same as in the row before I want to skip to the next row automatically and try it again.

If they are not the same, in an additional column it should add the value "1"

 

IDColourPrevious ColourIndex
126443RedGreen1
123456BlueRed2
175332BlueRed3
765432YellowBlue4
733511GreenYellow5
531534BlueGreen6

 

Something like: 

if ((PrevColour(index-1) = PrevColour(index) && Colour(index-1) = Colour(index))
then jump to index+1
else type "1" in new column

 

I'd appreciate any help. Kind regards 🙂

Jama1234

1 ACCEPTED SOLUTION
artemus
Microsoft Employee
Microsoft Employee

1. Add a new column: Index2 as an index column starting at 2 (one more than column Index)

2. Do a self join (Merge Tables) with Index and Index2 as the key joining columns. Kind of join is left outer

3. Expand the newly generated column to new rows.

4. Now you have duplicate columns in your table with values equal to the previous row.

5. Add a column that compares the current values with the previous values that are stored in the same row.

6. Remove unneeded columns

View solution in original post

2 REPLIES 2
artemus
Microsoft Employee
Microsoft Employee

1. Add a new column: Index2 as an index column starting at 2 (one more than column Index)

2. Do a self join (Merge Tables) with Index and Index2 as the key joining columns. Kind of join is left outer

3. Expand the newly generated column to new rows.

4. Now you have duplicate columns in your table with values equal to the previous row.

5. Add a column that compares the current values with the previous values that are stored in the same row.

6. Remove unneeded columns

Anonymous
Not applicable

It worked really well.

Thank you!!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.