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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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

 

 

abimf_1-1654860284503.png

 

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

1 REPLY 1
Anonymous
Not applicable

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 : https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-python-in-query-editor 

 

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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