Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!
Hi,
I have 3 columns sorted on Product and Order#. I want to create a flag (4th column) based on this condition which works in excel like this -> =IF(AND(A2=A1,B2=B1,C2<>C1),1,0). I am not sure how to implement this I Power Query Editor in PBI on large set of data. Can someone please help?
Thanks,
Anuj
Solved! Go to Solution.
Hi, @itsmeanuj
Could you please tell me whether your problem has been solved?
You can also try a formula as below:
flag =
VAR current_index = 'Table'[Index]
VAR pre_product =
CALCULATE (
MAX ( 'Table'[Product] ),
FILTER ( 'Table', 'Table'[Index] = current_index - 1 )
)
VAR pre_Order =
CALCULATE (
MAX ( 'Table'[Order#] ),
FILTER ( 'Table', 'Table'[Index] = current_index - 1 )
)
VAR pre_lot =
CALCULATE (
MAX ( 'Table'[LOT] ),
FILTER ( 'Table', 'Table'[Index] = current_index - 1 )
)
RETURN
IF ( [Product] = pre_product && [Order#] = pre_Order && [Lot] <> pre_lot, 1, 0 )
Best Regards,
Community Support Team _ Eason
Hi, @itsmeanuj
Could you please tell me whether your problem has been solved?
You can also try a formula as below:
flag =
VAR current_index = 'Table'[Index]
VAR pre_product =
CALCULATE (
MAX ( 'Table'[Product] ),
FILTER ( 'Table', 'Table'[Index] = current_index - 1 )
)
VAR pre_Order =
CALCULATE (
MAX ( 'Table'[Order#] ),
FILTER ( 'Table', 'Table'[Index] = current_index - 1 )
)
VAR pre_lot =
CALCULATE (
MAX ( 'Table'[LOT] ),
FILTER ( 'Table', 'Table'[Index] = current_index - 1 )
)
RETURN
IF ( [Product] = pre_product && [Order#] = pre_Order && [Lot] <> pre_lot, 1, 0 )
Best Regards,
Community Support Team _ Eason
@itsmeanuj , for that you need an index column https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi
then new column in DAX
= var _prd = maxx(filter(Table,[Index] =earlier([Index]) -1) , [Product])
var _ord = maxx(filter(Table,[Index] =earlier([Index]) -1) , [Order#])
var _Lot= maxx(filter(Table,[Index] =earlier([Index]) -1) , [Lot])
retrun
if([Product]=_prd && [Order #] =_ord && [Lot] <> _lot,1,0)
The Power BI Data Visualization World Championships is back! It's time to submit your entry.
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 56 | |
| 40 | |
| 38 | |
| 21 | |
| 21 |
| User | Count |
|---|---|
| 141 | |
| 103 | |
| 63 | |
| 36 | |
| 35 |