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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Grofu
Frequent Visitor

Percentage of orders which contains 2 or more colours

Hello,

 

Is there any possibility in DAX to create a column/measure to show me the % of orders that contains at least 2 colours ?

It seems that i cannot attach excels so this is what it should like:

 

Order   Product colour

AAA      White

BBB       Black

CCC       White

CCC      Black

 

Basically i have 3 different orders and one of them has (at least) 2 orders which means that it should return 33.33%.

 

I am able to do it with a visual to count distinct the colours per orders but i want a percentage as well (visual is not helping since i have too many lines to extract in excel).

 

Thanks

1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @Grofu ,

 

Try the measures:

 

count_color = 
CALCULATE(
    DISTINCTCOUNT(Sheet10[Product colour]),
    ALLEXCEPT(
        Sheet10,
        Sheet10[Order]
    )
)

count_order = 
CALCULATE(
    DISTINCTCOUNT(Sheet10[Order]),
    FILTER(
        Sheet10,
        [count_color] >= 2
    )
)

Percentage = 
VAR x = 
CALCULATE(
    DISTINCTCOUNT(Sheet10[Order]),
    ALL(Sheet10)
)
RETURN
DIVIDE(
    [count_order],
    x,
    BLANK()
)

g3.PNG

 

Best regards,
Lionel Chen

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

4 REPLIES 4
v-lionel-msft
Community Support
Community Support

Hi @Grofu ,

 

Try the measures:

 

count_color = 
CALCULATE(
    DISTINCTCOUNT(Sheet10[Product colour]),
    ALLEXCEPT(
        Sheet10,
        Sheet10[Order]
    )
)

count_order = 
CALCULATE(
    DISTINCTCOUNT(Sheet10[Order]),
    FILTER(
        Sheet10,
        [count_color] >= 2
    )
)

Percentage = 
VAR x = 
CALCULATE(
    DISTINCTCOUNT(Sheet10[Order]),
    ALL(Sheet10)
)
RETURN
DIVIDE(
    [count_order],
    x,
    BLANK()
)

g3.PNG

 

Best regards,
Lionel Chen

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

Anonymous
Not applicable

First create a calculated column that count the list of distinct colours

DistinctColours=
var thisOrder=YourTable[Order]
RETURN
DISTINCTCOUNT(FILTER(YourTable;YourTable[Order]=thisOrder);YourTable[ProductColor])

This should return

Order   Product colour DistinctColours

AAA      White              1

BBB       Black               1

CCC       White             2

CCC      Black               2

Unless you already have a "Orders" table (I suppose not, by looking at your example) now the next step is to summarize (group) your table to have a order table

Orders=SUMMARIZE(YourTable;YourTable[Order];YourTable[DistinctColours])

And this will generate

Order    DistinctColours

AAA             1

BBB               1

CCC             2


Then...I'll leave the next steps to you 🙂

Notice that I split this in several steps but it can be done in a single operation. This way is more explanatory

 

Thanks for your tip!

 

However it is not working because Distinctount does not allow me to use 2 parameters (filter+ product colours).

 

 

DistinctColours=
var thisOrder=YourTable[Order]
RETURN
DISTINCTCOUNT(FILTER(YourTable;YourTable[Order]=thisOrder);YourTable[ProductColor])

Too many arguments were passed to the DISTINCTCOUNT function. The maximum argument count for the function is 1.

Anonymous
Not applicable

Yeah, I did write the DAX on the fly ehehe

var thisOrder=YourTable[Order]
RETURN
CALCULATE(DISTINCTCOUNT(YourTable[ProductColor]);
filter(YourTable;YourTable[Order]=thisOrder)
)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.