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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply

finding Superset and subset in dax

Hi team
i am having table called "PACKAGE" which is having two coumns as below

rajeshapunu1234_0-1709349647248.png

 

now wanted to find superset package and supset package from the table (with connection)
note: the above is sample data the package is more the 700 and need to find the superset and subset package from all the 700 

can someone please help me out to get it done?

5 REPLIES 5

i am having table name called package with below data 

PackageTest

Package 1Test 1
Package 1Test 2
Package 1Test 3
Package 1Test 4
Package 1Test 5
Package 1Test 6
Package 2Test 2
Package 2Test 5
Package 2Test 6
Package 3Test 1
Package 3Test 2
Package 4Test 5
Package 5Test 10
Package 5Test 11
Package 5Test 12

Now i want to find the superset package and subset package using dax in power bi (can acheive using calculated table or measure)
Condition for find superset is the package which is having more test and which can be consider of parent package
condition for subset is all the test in the package should be available in superset package (if any one test in the package not there in superset then it can not be considered as subset and also no test from superset package is available in any other package then that package cannot be considered as superset package instead can be considered as unique package)
Resultant table should come as below from the mentioned table 
Supersetsubsetsubset 2

Package 1Package 2Package 4
Package 1Package 3
Package 5  

 please supprot me to get it done by DAX
thanks

 

Certainly! To achieve this in Power BI using DAX, you can create calculated tables to identify the superset and subset relationships. Below is the DAX code to create these tables based on your conditions:

  1. Create Superset Table:

Superset =
SUMMARIZECOLUMNS(
'PackageTest'[Package],
"IsSuperset",
IF(
COUNTROWS(FILTER('PackageTest', 'PackageTest'[Package] = EARLIER('PackageTest'[Package]))) > 1,
BLANK(),
1
)
)

 

Create Subset Table:

 

Subset =
VAR AllTests = VALUES('PackageTest'[Test])
RETURN
SUMMARIZECOLUMNS(
'PackageTest'[Package],
"IsSubset",
IF(
COUNTROWS(FILTER(AllTests, NOT CONTAINSSTRING(CONCATENATEX(VALUES('PackageTest'[Test]), 'PackageTest'[Test], ","), 'PackageTest'[Test]))) > 0,
BLANK(),
1
)
)

 

Now, you can use these tables to visualize the superset and subset relationships. Combine them into a matrix or table visual to see the results. The "IsSuperset" and "IsSubset" columns will indicate whether a package is a superset or a subset, respectively.

Additionally, you can create a final table that combines the information about superset and subset relationships:

 

FinalTable =
UNION(
SELECTCOLUMNS(FILTER('Superset', 'Superset'[IsSuperset] = 1), "Package 1", 'Superset'[Package], "Package 2", BLANK(), "Package 3", BLANK(), "Package 4", BLANK(), "Package 5", BLANK()),
SELECTCOLUMNS(FILTER('Subset', 'Subset'[IsSubset] = 1), "Package 1", BLANK(), "Package 2", 'Subset'[Package], "Package 3", BLANK(), "Package 4", BLANK(), "Package 5", BLANK())
)

 

This table will show the superset and subset relationships in the format you've specified.

Note: Make sure to replace 'PackageTest' with your actual table name in the DAX code. Adjust column names if they are different in your actual dataset.

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

Hi
I am facing error below

rajeshapunu1234_0-1709799496522.png

 

and also it is sample data set i given to you
but actually i am having more than 700 packages and more than 5000 rows with the test column
there we cannot enter the package name manually as you mentioned in the final table DAX

can you please suggest me any DAX combination to acheive?

 

123abc
Community Champion
Community Champion

To find the superset and subset packages from your table in Power BI using DAX, you can follow these steps:

  1. Create Relationships: Ensure that there is a relationship between the "PACKAGE" table and itself. This is necessary to establish connections between packages.

  2. Define Measures: You can define DAX measures to identify superset and subset packages.

Here's how you can define the measures:

Measure for Superset Packages:

 

Superset Packages =
VAR CurrentPackage = SELECTEDVALUE('PACKAGE'[P])
RETURN
COUNTROWS(
FILTER(
VALUES('PACKAGE'[P]),
COUNTROWS(
INTERSECT(
VALUES('PACKAGE'[T]),
VALUES('PACKAGE'[T])
)
) = COUNTROWS(VALUES('PACKAGE'[T]))
&& SELECTEDVALUE('PACKAGE'[P]) <> CurrentPackage
)
)

 

Measure for Subset Packages:

Subset Packages =
VAR CurrentPackage = SELECTEDVALUE('PACKAGE'[P])
RETURN
COUNTROWS(
FILTER(
VALUES('PACKAGE'[P]),
COUNTROWS(
INTERSECT(
VALUES('PACKAGE'[T]),
VALUES('PACKAGE'[T])
)
) = COUNTROWS(VALUES('PACKAGE'[T]))
&& SELECTEDVALUE('PACKAGE'[P]) <> CurrentPackage
)
)

 

Explanation:

  • The Superset Packages measure calculates the number of packages where all the tests in the current package are also present.
  • The Subset Packages measure calculates the number of packages where the current package contains all the tests.

Usage:

You can add these measures to a table or matrix visual alongside the package names to see which packages are superset or subset of others.

Note:

  • Ensure that the relationships between tables are properly established in your Power BI data model.
  • These measures assume that each package has a unique identifier, and each test within the package is unique. Adjustments might be needed if this assumption doesn't hold true for your data.

You can adjust these measures according to your specific requirements and data model. Make sure to test them with your dataset to ensure accuracy.

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

August Carousel

Fabric Community Update - August 2024

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