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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ngct1112
Post Patron
Post Patron

DAX - Finding the possible combination for all items

Hi All, I am trying to solve a problem in the PowerBI model.

There are 15 items need to be produced. I have classified the Suppliers from the cheapest to the most expensive.

I am now trying to determine the bundled production with 1 supplier or 2 supplier or more.

 

Dateset:

IDTop 1 SupplierTop 2 SupplierTop 3 Supplier
1Supplier ASupplier BSupplier C
2Supplier BSupplier A 
3Supplier CSupplier A 
4Supplier ASupplier BSupplier C
5Supplier ASupplier B 
6Supplier BSupplier CSupplier A
7Supplier B  
8Supplier ASupplier BSupplier C
9Supplier A  
10Supplier ASupplier CSupplier B
11Supplier ASupplier BSupplier C
12Supplier BSupplier A 
13Supplier CSupplier ASupplier B
14Supplier BSupplier CSupplier A
15Supplier BSupplier C 

 

I am trying to find out the questions below,

1.) Is it possible only by using one Supplier could produce all those items?   Answer: No(Null)

2.) Is it possible by using 2 Suppliers could produce all those items? if yes, which two?   Answer: A & B

 

It is quite a tricky question and i have been trying to finding a solution for so long. Appreciated with any helps. Thanks.

1 ACCEPTED SOLUTION

hi  @ngct1112 

For you want to show Combination Supplier, I would suggest you create measure for each output

Supplier A = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] = "Supplier A"))
Supplier B = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] = "Supplier B"))

Supplier C = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] = "Supplier C"))

Supplier A&B = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] IN {"Supplier A", "Supplier B"}))

Supplier A&C = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] IN {"Supplier A", "Supplier C"}))

Supplier B&C = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] IN {"Supplier C", "Supplier B"}))

Result:

9.JPG

 

or another way as below:

Step1 :

Use this formula to create a dim Combination table

Dim Supplier = 
var _supplier1=SELECTCOLUMNS(VALUES(Supplier[Supplier]),"Supplier 1",[Supplier])
var _supplier2=SELECTCOLUMNS(VALUES(Supplier[Supplier]),"Supplier 2",[Supplier])
return

ADDCOLUMNS(GENERATE(_supplier1,_supplier2),
"Combination",CONCATENATEX(DISTINCT(UNION(ROW("Supplier",[Supplier 1]),ROW("Supplier",[Supplier 2]))),[Supplier]," or ",[Supplier],ASC))

 

Step2:

Create a measure as below:

Products Measure =
 CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] in VALUES('Dim Supplier'[Supplier 1])||Supplier[Supplier] in VALUES('Dim Supplier'[Supplier 2])))

Step3:

Now drag Combination field from dim table and this meausre into visual

10.JPG

 

here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

Your requirement is not clear.  Why should the answer be 15 products for A&B?  Supplier A cannot product Product 7.  Please explain.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks @Ashish_Mathur I would like to find the maximum products each combination could produce, hope this Table could explain better:

 

 

IDTop 1 GroupTop 2 GroupTop 3 Group Supplier ASupplier BSupplier CSupplier A or B Supplier B or CSupplier A or C
1Supplier ASupplier BSupplier C YYYYYY
2Supplier BSupplier A  YYNYYY
3Supplier CSupplier A  YNYYYY
4Supplier ASupplier BSupplier C YYYYYY
5Supplier ASupplier B  YYNYYY
6Supplier BSupplier CSupplier A YYYYYY
7Supplier B   NYNYYN
8Supplier ASupplier BSupplier C YYYYYY
9Supplier A   YNNYNY
10Supplier ASupplier CSupplier B YYYYYY
11Supplier ASupplier BSupplier C YYYYYY
12Supplier BSupplier A  YYNYYY
13Supplier CSupplier ASupplier B YYYYYY
14Supplier BSupplier CSupplier A YYYYYY
15Supplier BSupplier C  NYYYYY
     131310151414

 

Desired Outcome:

Combination:Products
Supplier A13
Supplier B13
Supplier C10
Supplier A or B 15
Supplier B or C14
Supplier A or C14

Hi,

I am still not clear.  You are saying that whether i hire Supplier A or B, i will be able to produce 15 items.  That is clearly not correct because Supplier A cannot produce item 7.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

hi  @ngct1112 

For you want to show Combination Supplier, I would suggest you create measure for each output

Supplier A = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] = "Supplier A"))
Supplier B = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] = "Supplier B"))

Supplier C = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] = "Supplier C"))

Supplier A&B = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] IN {"Supplier A", "Supplier B"}))

Supplier A&C = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] IN {"Supplier A", "Supplier C"}))

Supplier B&C = CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] IN {"Supplier C", "Supplier B"}))

Result:

9.JPG

 

or another way as below:

Step1 :

Use this formula to create a dim Combination table

Dim Supplier = 
var _supplier1=SELECTCOLUMNS(VALUES(Supplier[Supplier]),"Supplier 1",[Supplier])
var _supplier2=SELECTCOLUMNS(VALUES(Supplier[Supplier]),"Supplier 2",[Supplier])
return

ADDCOLUMNS(GENERATE(_supplier1,_supplier2),
"Combination",CONCATENATEX(DISTINCT(UNION(ROW("Supplier",[Supplier 1]),ROW("Supplier",[Supplier 2]))),[Supplier]," or ",[Supplier],ASC))

 

Step2:

Create a measure as below:

Products Measure =
 CALCULATE(DISTINCTCOUNT(Supplier[ID]),FILTER(Supplier,Supplier[Supplier] in VALUES('Dim Supplier'[Supplier 1])||Supplier[Supplier] in VALUES('Dim Supplier'[Supplier 2])))

Step3:

Now drag Combination field from dim table and this meausre into visual

10.JPG

 

here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-lili6-msft Your solution is indeed so brilliant. Appreciated with your great help. I will take method 1 in my model.

amitchandak
Super User
Super User

@ngct1112 , is it only three or this just sample, you can have n number suppliers and have top3

@ngct1112 , I unpivoted the table and created one analysis. That can answer, your questions

 

@amitchandak. Thanks for it, but how could the table show Supplier A & B are sufficient to produce all 15 products?

The table is showing how many products each supplier can produce respectively in the "products" column?

 

ngct1112_0-1598407036126.png

 

Is it possible to show something like 

Supplier A: 13

Supplier B: 13

Supplier C: 10

A & B: 15

A & C: 14

 

Thanks @amitchandak you are correct. This is just a sample and there could be different number of supplier for different project.

Some times it may take more supplier to fulfil to production.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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