Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello,
i have a datasource like following
Product Code | Category |
P1 | A |
P1 | B |
P1 | C |
P2 | B |
P3 | A |
P3 | C |
P4 | A |
That means any product can be in one or more categories.
I need to build a cross table nxn where n is number of catagories like following
A | B | C | |
A | 3 | 1 | 2 |
B | 1 | 2 | 0 |
C | 2 | 0 | 2 |
In each field is a count of products that has a record for both categories in row and column. For example field AC = CA = 2 means that there are exactly 2 products that have both catagory A and C - namely P1 and P3.
How can I construct this in PivotTable using DAX?
Solved! Go to Solution.
Hi,
Please check the below picture and the attached pbix file.
One of ways is to create a datamodel like below.
Count products measure: =
VAR _basketA =
CALCULATETABLE (
DISTINCT ( Data[Product Code] ),
ALL ( 'Category basket B'[Category] )
)
VAR _basketB =
CALCULATETABLE (
DISTINCT ( Data[Product Code] ),
ALL ( 'Category basket A'[Category] )
)
RETURN
IF (
HASONEVALUE ( 'Category basket A'[Category] )
&& HASONEVALUE ( 'Category basket B'[Category] ),
COUNTROWS ( INTERSECT ( _basketA, _basketB ) )
)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Schedule a short Teams meeting to discuss your question.
Thank you, works great
Hi @jirim
Please refer to attached sample file with the solution
Count =
VAR Cat1 = SELECTEDVALUE ( Category1[Category] )
VAR Cat2 = SELECTEDVALUE ( Category2[Category] )
VAR Prodcuts1 = CALCULATETABLE ( VALUES ( 'Table'[Product Code] ), 'Table'[Category] = Cat1 )
VAR Prodcuts2 = CALCULATETABLE ( VALUES ( 'Table'[Product Code] ), 'Table'[Category] = Cat2 )
RETURN
COUNTROWS (
INTERSECT ( Prodcuts1, Prodcuts2 )
)
Hi,
Please check the below picture and the attached pbix file.
One of ways is to create a datamodel like below.
Count products measure: =
VAR _basketA =
CALCULATETABLE (
DISTINCT ( Data[Product Code] ),
ALL ( 'Category basket B'[Category] )
)
VAR _basketB =
CALCULATETABLE (
DISTINCT ( Data[Product Code] ),
ALL ( 'Category basket A'[Category] )
)
RETURN
IF (
HASONEVALUE ( 'Category basket A'[Category] )
&& HASONEVALUE ( 'Category basket B'[Category] ),
COUNTROWS ( INTERSECT ( _basketA, _basketB ) )
)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Schedule a short Teams meeting to discuss your question.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
11 | |
10 | |
10 | |
9 |
User | Count |
---|---|
18 | |
13 | |
12 | |
11 | |
8 |