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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
amrutamore25
Regular Visitor

Compare rows from column having same saleId

I need to compare two rows in a column which has same saleId and count the number of occurrences of one of the values. Please find the example below.

 

SaleIDProduct Name
1Product 1
1Product 2 
1Product 3
2Product 1x
2Product 2 
2Product 3
3Product 1
3Product 2 
3Product 3

 

I need to find the count of 'Product 2' having 'Product 1' with same SaleID. It shouldn't include 'Product 2' having 'Product 1x' with same SaleID.

1 ACCEPTED SOLUTION
Mahesh0016
Super User
Super User

@amrutamore25  I hope this helps you. Thank You.
Count_Product2_with_Product1 =
CALCULATE(
COUNTROWS(YourTable),
FILTER(
YourTable,
YourTable[Product Name] = "Product 2" &&
CALCULATE(
COUNTROWS(YourTable),
FILTER(
YourTable,
YourTable[Product Name] = "Product 1" &&
YourTable[SaleID] = EARLIER(YourTable[SaleID])
)
) > 0 &&
NOT(
CALCULATE(
COUNTROWS(YourTable),
FILTER(
YourTable,
YourTable[Product Name] = "Product 1x" &&
YourTable[SaleID] = EARLIER(YourTable[SaleID])
)
) > 0
)
)
)

View solution in original post

2 REPLIES 2
amrutamore25
Regular Visitor

Thank you @Mahesh0016 !
Your solution is working as expected.

Mahesh0016
Super User
Super User

@amrutamore25  I hope this helps you. Thank You.
Count_Product2_with_Product1 =
CALCULATE(
COUNTROWS(YourTable),
FILTER(
YourTable,
YourTable[Product Name] = "Product 2" &&
CALCULATE(
COUNTROWS(YourTable),
FILTER(
YourTable,
YourTable[Product Name] = "Product 1" &&
YourTable[SaleID] = EARLIER(YourTable[SaleID])
)
) > 0 &&
NOT(
CALCULATE(
COUNTROWS(YourTable),
FILTER(
YourTable,
YourTable[Product Name] = "Product 1x" &&
YourTable[SaleID] = EARLIER(YourTable[SaleID])
)
) > 0
)
)
)

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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