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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
tonyclifton
Helper III
Helper III

DAX formula to get the correct count

Hello community,


in below image I have an overall status for a product (47%). Now I'm looking for a formula that will give me the according color (Red) for that number which I only get to work with a measure in a card visual for example.

Hoewever in the pie chart I need to use a column which should only show one color for each product.

2019-05-02 12_51_45-color - Power BI Desktop.png

This is my statement for the Color and ColorMeasure column in the table above:

Color = SWITCH (
    TRUE ();
    [Status in %] >= 0 &&  [Status in %] < 0,8; "Red";
    [Status in %] >= 0,8 &&  [Status in %] < 1; "Yellow";
    [Status in %] = 1; "Green"; BLANK())

 

Status in % = 
var statusResult = CALCULATE (
    COUNTROWS ( 'Product' )
    )

var init =  DIVIDE(CALCULATE(sum('Product'[Status]));100)
var result =  CALCULATE(DIVIDE(init;statusResult))
return result


What do I need to do to get the pie chart working correctly?

 

Thank you.

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

hi, @tonyclifton 

If you could try this way:

Step1:

Add a dim color table(Don't create the relationship with any table)

2.JPG

Step2:

add a new measure like this:

Measure 3 = IF(SELECTEDVALUE('Dim Color'[Color])=[Color Measure],[Status in %])

Step3:

For pie chart, drag color field from dim color table and the measure into pie chart.

Result:

3.JPG

 

and here is pbix file, please try it.

 

If not your case, please share your sample data and your expected output form.

 

Best 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

1 REPLY 1
v-lili6-msft
Community Support
Community Support

hi, @tonyclifton 

If you could try this way:

Step1:

Add a dim color table(Don't create the relationship with any table)

2.JPG

Step2:

add a new measure like this:

Measure 3 = IF(SELECTEDVALUE('Dim Color'[Color])=[Color Measure],[Status in %])

Step3:

For pie chart, drag color field from dim color table and the measure into pie chart.

Result:

3.JPG

 

and here is pbix file, please try it.

 

If not your case, please share your sample data and your expected output form.

 

Best 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.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.