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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
alawode
Helper I
Helper I

Count Based on specific values in column

Hi Experts,

I have a  table of cars and thier Models (Which i have attached ). I am trying to get a count of only the cars that have the "Fault " Value in them. For example, Toyota should completely be excluded from the count in the 'Count of Car Model' since none of its cars have 'Fault' in the 'Car Model" column. So the result should be :Total Count should be "7" and toyota should not show up in the 'Cars" column at all.

Thanks in advanceCar Models.PNG

1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @alawode ,

 

You can write below measure for getting required output:-

 

Fault_Car = 
VAR _max =
    MAX ( Car_detail[Car] )
VAR result =
    CALCULATE (
        COUNTROWS ( Car_detail ),
        FILTER (
            ALL ( Car_detail ),
            Car_detail[Car] = _max
                && Car_detail[Model] = "fault"
        )
    )
RETURN
    IF ( ISBLANK ( result ), 0, result )

 

Output:-

image.png

As you can see total not showing correct so for that you need to write another measure:-

 

Corrected_total = 
SUMX (
    SUMMARIZE ( Car_detail, Car_detail[Car], Car_detail[Model], "Sum", [Fault_Car] ),
    [Sum]
)

 

Output:-

Samarth_18_0-1632891290254.png

Note:- Both measure need to create to get a final ouput.

 

Thank you,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

3 REPLIES 3
Samarth_18
Community Champion
Community Champion

Hi @alawode ,

 

You can write below measure for getting required output:-

 

Fault_Car = 
VAR _max =
    MAX ( Car_detail[Car] )
VAR result =
    CALCULATE (
        COUNTROWS ( Car_detail ),
        FILTER (
            ALL ( Car_detail ),
            Car_detail[Car] = _max
                && Car_detail[Model] = "fault"
        )
    )
RETURN
    IF ( ISBLANK ( result ), 0, result )

 

Output:-

image.png

As you can see total not showing correct so for that you need to write another measure:-

 

Corrected_total = 
SUMX (
    SUMMARIZE ( Car_detail, Car_detail[Car], Car_detail[Model], "Sum", [Fault_Car] ),
    [Sum]
)

 

Output:-

Samarth_18_0-1632891290254.png

Note:- Both measure need to create to get a final ouput.

 

Thank you,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18  Thanks for the help, quick question, for some reason the formula is not picking up 20 cars in the bigger table, and all of them have "fault", do you know how to tweak the expression to recify the issue? Thanks

@Samarth_18Thanks a lot for this, it worked well

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Top Solution Authors