Forum Discussion

Saxon10's avatar
Saxon10
Post Prodigy
5 years ago
Solved

SWITCH TRUE same column contain multiple status

Hi,   I have 9 columns are UK, US, INDIA, SA, SRL, PAK,BAN ,AFG and ENG (from column B:J and column K is my final result in Excel), each columns contain multiple status.   UK US INDIA ...
  • mahoneypat's avatar
    5 years ago

    The data should be unpivoted.  See the attached pbix in the Data2 query.  After that, a measure expression like this one can be used to get your result in a table visual with your Item column.

     

    Status =
    VAR vCtoI =
        CALCULATE (
            COUNTROWS ( DATA2 ),
            DATA2[Value] = "NOT MATCHED",
            FILTER (
                ALL ( DATA2[Attribute] ),
                NOT ( DATA2[Attribute]
                    IN {
                    "ENG",
                    "UK"
                )
            )
        ) > 0
    VAR vEngUK =
        AND (
            CALCULATE (
                COUNTROWS ( DATA2 ),
                DATA2[Value] = "NOT REQUIRED",
                DATA2[Attribute] = "UK"
            ) > 0,
            CALCULATE (
                COUNTROWS ( DATA2 ),
                DATA2[Value] = "NOT MATCHED",
                DATA2[Attribute] = "ENG"
            ) > 0
        )
    RETURN
        IF (
            OR (
                vCtoI,
                vEngUK
            ),
            "NOT COMPLETED",
            "COMPLETED"
        )

     

    Regards,

    Pat

  • v-alq-msft's avatar
    5 years ago

    Hi, Saxon10 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

    Table:

     

    You may create a calculated column or a measure as below.

    Calculated column:

    Status Column = 
    var b=[UK]
    var ci={[US],[INDIA],[SA],[SRL],[PAK],[BAN],[AFG]}
    var j=[ENG]
    return
    SWITCH(
        TRUE(),
        b="Matched"&&COUNTROWS(ci)=COUNTROWS(FILTER(ci,[Value]="Matched"))&&j="Not Required",
        "Completed",
        b="Not Required"&&COUNTROWS(ci)=COUNTROWS(FILTER(ci,[Value]="Matched"))&&j="Not Required",
        "Completed",
        b="Not Required"&&COUNTROWS(ci)=COUNTROWS(FILTER(ci,[Value]="Matched"))&&j="Matched",
        "Completed",
        b="Not Required"&&COUNTROWS(ci)=COUNTROWS(FILTER(ci,[Value]="Matched"))&&j="Not Matched",
        "Not Completed",
        COUNTROWS(ci)<>COUNTROWS(FILTER(ci,[Value]="Matched")),
        "Not Completed"
    )

     

    Measure:

    Status Measure = 
    var b=MAX('Table'[UK])
    var ci={MAX('Table'[US]),MAX('Table'[INDIA]),MAX('Table'[SA]),MAX('Table'[SRL]),MAX('Table'[PAK]),MAX('Table'[BAN]),MAX('Table'[AFG])}
    var j=MAX('Table'[ENG])
    return
    SWITCH(
        TRUE(),
        b="Matched"&&COUNTROWS(ci)=COUNTROWS(FILTER(ci,[Value]="Matched"))&&j="Not Required",
        "Completed",
        b="Not Required"&&COUNTROWS(ci)=COUNTROWS(FILTER(ci,[Value]="Matched"))&&j="Not Required",
        "Completed",
        b="Not Required"&&COUNTROWS(ci)=COUNTROWS(FILTER(ci,[Value]="Matched"))&&j="Matched",
        "Completed",
        b="Not Required"&&COUNTROWS(ci)=COUNTROWS(FILTER(ci,[Value]="Matched"))&&j="Not Matched",
        "Not Completed",
        COUNTROWS(ci)<>COUNTROWS(FILTER(ci,[Value]="Matched")),
        "Not Completed"
    )

     

    Result:

     

    Best Regards

    Allan

     

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