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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register 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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors