Forum Discussion

cathoms's avatar
cathoms
Responsive Resident
4 years ago
Solved

Using SWITCH for multiple conditions with AND & SEARCH

Hi. I need to flag medical procedure code changes and have an original procedure code column, a current procedure code column, and a calculated column for the numeric difference betweens the procedure codes. Most codes are 5 digits.

 

I have one bit of procedure code change that is a bit finicky, as follows:

  1. Anything that goes from/between a 9938X to a 9938X would be Neutral
  2. Anything that goes from/between a 9939X to a 9939X would be Neutral

Here is what I came up with to create a new column:

CodeChangeFlag2 = 
    SWITCH (
        TRUE (),
        SEARCH("NCG",UclFact[OriginalProcedureFinal],1,0) = 1, "Up Coded",
        SEARCH("NCG",UclFact[CurrentProcedureFinal],1,0) = 1, "Down Coded",
        SEARCH("G",UclFact[CurrentProcedureFinal],1,0) = 1, "Neutral",
        SEARCH("99999",UclFact[OriginalProcedureFinal],1,0) = 1, "Up Coded",
        SEARCH("9938",UclFact[OriginalProcedureFinal],1,0) = 1, && SEARCH("9938"UclFact[CurrentProcedureFinal],1,0) = 1, "Neutral",
        SEARCH("9939",UclFact[OriginalProcedureFinal],1,0) = 1 && SEARCH("9939"UclFact[CurrentProcedureFinal],1,0) = 1, "Neutral",
        ISBLANK(UclFact[CodingChange]),"Unclassified",
        UclFact[CodingChange] = -1, "Up Coded",
        UclFact[CodingChange] = -2, "Up Coded",
        UclFact[CodingChange] = -11, "Up Coded",
        UclFact[CodingChange] = -12, "Up Coded",
        UclFact[CodingChange] = 9, "Up Coded",
        UclFact[CodingChange] = 238, "Up Coded",
        UclFact[CodingChange] = 228, "Up Coded",
        UclFact[CodingChange] = 227, "Up Coded",
        UclFact[CodingChange] = 208, "Up Coded",
        UclFact[CodingChange] = -10, "Neutral",
        UclFact[CodingChange] = 10, "Neutral",
        UclFact[CodingChange] < -99, "Neutral",
        UclFact[CodingChange] > 99, "Neutral",
        UclFact[CodingChange] = 1, "Down Coded",
        UclFact[CodingChange] = 11, "Down Coded",
        UclFact[CodingChange] = 0, "No Change"
    )

 DAX doesn't like the two statements with &&. Without those the DAX works just fine. The accepted solution in Switch with multiple conditions suggests that in general this should work but maybe it doesn't work with SEARCH? There is probably some different approach that would work. Any ideas? Maybe using variables but I'm not very well versed in those.

 

Any help would be much appreciated!

2 Replies

    • cathoms's avatar
      cathoms
      Responsive Resident

      Ha! Good catch! Not only did I have an extra comma but I was also missing a couple of commas in those two lines...

      Thanks so much!