Forum Discussion

_Kelz0484's avatar
_Kelz0484
Frequent Visitor
1 year ago
Solved

DAX for finding matches in multiple columns

Hi, Hope I'm posting this in the right place. I'm trying to write a DAX command to find if a column that contains a certificate number matches two other columns within the same table. Column 1 Cer...
  • johnt75's avatar
    1 year ago

    You could create a calculated column like

    Match =
    VAR DateToCheck =
        RIGHT ( 'Table'[Column1], 10 )
    VAR NumberToCheck =
        LEFT ( 'Table'[Column1], 20 ) -- Replace the logic here as needed
    VAR AllSerialNos =
        CALCULATETABLE ( ALL ( 'Table'[Column2] ), 'Table'[Column4] = DateToCheck )
    VAR AllBatchNos =
        CALCULATETABLE ( ALL ( 'Table'[Column3] ), 'Table'[Column4] = DateToCheck )
    VAR Result =
        IF (
            NumberToCheck
                IN AllSerialNos
                    || NumberToCheck IN AllBatchNos,
            "Match",
            "Discrepancy"
        )
    RETURN
        Result
    

    You'll need to change the logic splitting out the number from the date appropriately, and you may need to manipulate the date data to get it in date format to match Column4