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!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
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.
SaleID | Product Name |
1 | Product 1 |
1 | Product 2 |
1 | Product 3 |
2 | Product 1x |
2 | Product 2 |
2 | Product 3 |
3 | Product 1 |
3 | Product 2 |
3 | Product 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.
Solved! Go to Solution.
@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
)
)
)
@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
)
)
)
User | Count |
---|---|
15 | |
9 | |
8 | |
6 | |
5 |
User | Count |
---|---|
31 | |
18 | |
13 | |
7 | |
5 |