Showing results for 
Search instead for 
Did you mean: 
New Member

if row equals to previous then 1 else 0

Hi everyone, 


I am trying to create a new column (or perhaps a measure) that will serve as a flag indicating if a row is equal to the previous row. if yes then 1 else 0





In the above example, I want to be able to flag H12-12 | Red as 0 and H12-13 | Pink as 0 while the rest as 1. 


Any tips on how to this will be superhelpful

Frequent Visitor

PBI doesn't really 'sort' data when processing.


If your dataset isn't too big, you could use a python script in the power Query editor

First add a blank column (Add a column -> custom column) (in my example I named it column4). The python script would look like this :


prevline = ''
for data in dataset:
    data.column4 = 1 if (data.column1 == prevline) else 0
    prevline = data.column1



Here is the MS documentation on how to use Python in power Query : 


If this answer works, please mark it as a solution 🙂

Helpful resources

September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Show episode 9

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 25

Ted's Dev Camp - August 25, 2022

Watch Session 25 of Ted's Dev Camp.

Top Solution Authors