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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Adamkowalsky92
Frequent Visitor

DAX Measure - Co-occurrences

 

Hi, I'm having trouble coming up with a measurement.

Simple table, 2 columns, Invoice No. and Product. The task is to obtain the result of co-occurrences on one invoice.
I want to have a slicer with product selection and a table where I add a product column to the rows and this measure to the value. Selecting product 1 in the slicer will show me the remaining products and the number of co-occurrences on one of the invoices.
for example: let's assume that product 1 appeared on 100 invoices, it will show me that product 2 appeared 50 times out of these 100 invoices, product 3 20 times etc.


Example:

Invoice no.Product
1231
1232
1233
2341
2343
3451
3454
3455
4561
4562
4563
4564


Results, after choose Product 1 from slicer

ProductOccurreces
22
33
42
51




1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You'd need to create a separate table for use in the slicer. You can use

Product for slicer = DISTINCT( 'Table'[Product] )

Do not connect that to the main table, just use it in the slicer.

You can then create a measure like

[Num co-occurences] = IF(
SELECTEDVALUE('Product for slicer'[Product]) <> SELECTEDVALUE('Table'[Product]),
VAR InvoicesForChosenProduct = CALCULATETABLE(
	VALUES('Table'[Invoice no.]),
	TREATAS(
		VALUES('Product for slicer'[Product]),
		'Table'[Product]
	)
)
VAR InvoicesForCurrentProduct = VALUES('Table'[Invoice no.])
VAR Result = COUNTROWS(INTERSECT(
	InvoicesForChosenProduct,
	InvoicesForCurrentProduct
))
RETURN
	Result
)

and use the [Product] column from the main table in your visual.

View solution in original post

3 REPLIES 3
ThxAlot
Super User
Super User

It's solved already when I saw it; but just for fun only, I provide a more sophisticated solution applicable to a more generic model. What's more an intricacy of it is that when more products selected in the slicer (ie, product 1&2), only those invoices (invoice 123 & 456) containing all selected products will be further investigated for co-existing products (product 3&4).

ThxAlot_0-1733942015976.png

ThxAlot_1-1733942484960.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



johnt75
Super User
Super User

You'd need to create a separate table for use in the slicer. You can use

Product for slicer = DISTINCT( 'Table'[Product] )

Do not connect that to the main table, just use it in the slicer.

You can then create a measure like

[Num co-occurences] = IF(
SELECTEDVALUE('Product for slicer'[Product]) <> SELECTEDVALUE('Table'[Product]),
VAR InvoicesForChosenProduct = CALCULATETABLE(
	VALUES('Table'[Invoice no.]),
	TREATAS(
		VALUES('Product for slicer'[Product]),
		'Table'[Product]
	)
)
VAR InvoicesForCurrentProduct = VALUES('Table'[Invoice no.])
VAR Result = COUNTROWS(INTERSECT(
	InvoicesForChosenProduct,
	InvoicesForCurrentProduct
))
RETURN
	Result
)

and use the [Product] column from the main table in your visual.

Great, great, great! Exactly what i want! Thank you so much.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.