Forum Discussion

SCallanan's avatar
SCallanan
Frequent Visitor
2 years ago
Solved

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])

 

 

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

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    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":

    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:

    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:

     

    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.

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    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":

    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:

    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:

     

    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.

  • 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:

     

     

     

    If not please explain better what you need