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
SCallanan
Frequent Visitor

Filter and Replace values

Hi guys,

 

I want to filter and replace the SUM of the Distinctcount values  when Admin & physical both apply together and replace the total which would be 2 with 1. 

 

Please note, this is only an extract of the dataset. I already did the DistinctCount before with this measure: 

 

DistinctCountInspectionCategory = DISTINCTCOUNTNOBLANK('Inspections'[Inspection Group])

 

SCallanan_0-1722513681189.png

 

Sorry I couldn't paste all the values, but the relavent two ID's are included. 

 

Thanks for your help. 

Trip Inspection IdInspection GroupDistinctCountInspectionCategory
9090469Administrative1
600384Administrative1
600480Administrative1
600575Administrative1
600671Administrative1
600767Administrative1
793963Administrative1
793997Administrative1
794182Administrative1
794267Administrative1
826837Administrative1
829543Administrative1
829543Physical1
829588Administrative1
829588Physical1
928621Administrative1
928648Administrative1
928675Physical1
953030Administrative1
953104Physical1

 

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

Hi, @SCallanan 

I am glad to help you.

But I am not sure if I have understood your needs correctly.


Perhaps you could start by trying to create a calculated column that marks each Trip Inspection Id as having both "Administrative" and "Physical":

vfenlingmsft_0-1722579208213.png

HasBoth = 
VAR CurrentTripId = Inspections[Trip Inspection Id]
RETURN
    IF (
        CALCULATE (
            COUNTROWS ( Inspections ),
            Inspections[Trip Inspection Id] = CurrentTripId,
            Inspections[Inspection Group] = "Administrative"
        ) > 0
            && CALCULATE (
                COUNTROWS ( Inspections ),
                Inspections[Trip Inspection Id] = CurrentTripId,
                Inspections[Inspection Group] = "Physical"
            ) > 0,
        1,
        0
    )


Then create a Measure:

vfenlingmsft_1-1722579234693.png

TripInspectionIdCount = 
CALCULATE (
    DISTINCTCOUNT ( Inspections[Trip Inspection Id] ),
    Inspections[HasBoth] = 1
)
    + CALCULATE (
        DISTINCTCOUNT ( Inspections[Trip Inspection Id] ),
        Inspections[HasBoth] = 0
    )


Here is the final test result, hope it helps:

vfenlingmsft_2-1722579265148.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
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

3 REPLIES 3
v-fenling-msft
Community Support
Community Support

Hi, @SCallanan 

I am glad to help you.

But I am not sure if I have understood your needs correctly.


Perhaps you could start by trying to create a calculated column that marks each Trip Inspection Id as having both "Administrative" and "Physical":

vfenlingmsft_0-1722579208213.png

HasBoth = 
VAR CurrentTripId = Inspections[Trip Inspection Id]
RETURN
    IF (
        CALCULATE (
            COUNTROWS ( Inspections ),
            Inspections[Trip Inspection Id] = CurrentTripId,
            Inspections[Inspection Group] = "Administrative"
        ) > 0
            && CALCULATE (
                COUNTROWS ( Inspections ),
                Inspections[Trip Inspection Id] = CurrentTripId,
                Inspections[Inspection Group] = "Physical"
            ) > 0,
        1,
        0
    )


Then create a Measure:

vfenlingmsft_1-1722579234693.png

TripInspectionIdCount = 
CALCULATE (
    DISTINCTCOUNT ( Inspections[Trip Inspection Id] ),
    Inspections[HasBoth] = 1
)
    + CALCULATE (
        DISTINCTCOUNT ( Inspections[Trip Inspection Id] ),
        Inspections[HasBoth] = 0
    )


Here is the final test result, hope it helps:

vfenlingmsft_2-1722579265148.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Gabry
Super User
Super User

Hello,

@SCallanan I'm not sure what you need to do, you just need to distinctcount the trip ID?

 

If so, is as simple as this:

 

Gabry_0-1722515038860.png

 

 

If not please explain better what you need

Hi @Gabry 

It is really part of a bigger problem /Count-of-ID-with-filters-based-on-a-different-column-Values 

maybe it helps to understand the context if you have a look at that. 

Thanks so much, I'm trying to get this right for ages. 

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.