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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Count, for 2 different keys, the number of shared values

hello,

 

I have a table like this :

KeyValue
Store 1Apple
Store 1Orange
Store 2Apple
Store 2Banana
Store 2Orange
Store 3Banana
Store 3Orange

 

I would like to display a card where, when I select 2 stores, I get the number of values they have in common.

I tought of creating a table like that :

key 1key 2(Calculated column) Nb shared values
Store 1Store 22
Store 1Store 31
Store 2Store 12
Store 2Store 31
Store 3Store 11
Store 3Store 21

 

That way I can filter on key 1 and key 2 and display the Nb shared values.

 

Is it the right way to do it ? If yes, how do I compute the "Nb shared values" column with DAX ?

 

Thanks in advance for your help.

3 REPLIES 3
Anonymous
Not applicable

You have to have 2 tables with unique Stores only so that you can select 2 stores independently.

 

"Store 1" Table:

Key

Store 1

Store 2

Store 3

...

 

"Store 2" Table:

Key

Store 1

Store 2

Store 3

...

 

These tables will not be connected to the table that holds Key and Values. If one store is selected from Store 1 and one is selected from Store 2, then here's a measure that will calculate the number of values they have in common:

[# Values In Common] =
var __store1 = selectedvalue( 'Store 1'[Key] )
var __store2 = selectedvalue( 'Store 2'[Key] )
var __values1 =
	CALCULATETABLE(
		DISTINCT( StoresWithValues[Value] ),
		treatas( __store1, StoresWithValues[Key] )
	)
var __values2 =
	CALCULATETABLE(
		DISTINCT( StoresWithValues[Value] ),
		treatas( __store1, StoresWithValues[Key] )
	)
var __result =
	COUNTROWS(
		INTERSECT(
			__values1,
			__values2
		)
	)
return
	__result

 

Best

D

Greg_Deckler
Community Champion
Community Champion

Perhaps my In Common quick measure: https://community.powerbi.com/t5/Quick-Measures-Gallery/In-Common/m-p/382956#M117


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi Greg,

 

Thanks for your quick answer !

It looks like it coud be the solution 🙂 I will test it.

But can you please explain to us how did you construct your measure ? I don't get it ...

InCommon = 
VAR students1 = FILTER(ALL(Students),Students[Teacher]=MAX(Teachers[Teacher]))
VAR students1a = SELECTCOLUMNS(students1,"MyStudent",[Student])
VAR students2 = FILTER(ALL(Students),Students[Teacher]=MAX(Teachers2[Teacher]))
VAR students2a = SELECTCOLUMNS(students2,"MyStudent",[Student])
VAR incommon = COUNTROWS(INTERSECT(students1a,students2a))
RETURN IF(ISBLANK(incommon),0,incommon)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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