Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

How to extract the correct code

Hi,

 

I have a list of problem code and I wish to extract the information C162, C200 and C198 from the list.

How can I do that?

Example:

  1. DS (Dispenser) (C162) --ComA
  2. C200 Mechanical
  3. Hardware (C198) --Default

8 Replies

  • Hi Anonymous 

    This works with the examples you've supplied.  The query expects all error codes to start with C. 

    Copy andpaste the code below into a new blank query or use this  sample PBIX file showing it working

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcglW0HDJLC5IzStOLdJU0HA2NDPSVNDVdc7PdVSK1YlWcjYyMFDwTU3OSMzLTE7MAYt5JBallCcWpYKUW1qAlLukpiWW5pQoxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Problem Code" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Problem Code", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each "C"&Text.Combine(List.RemoveItems(Text.ToList(Text.Lower([Problem Code])),{"a" .. "z", "(",")"," ","-"})))
    in
        #"Added Custom"

     

     

    Phil


    If I answered your question please mark my post as the solution.
    If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.

  • Anonymous , What output you need is not very clear. Try new column like

    if( search("C162",[column],,0) >0 || search("C200",[column],,0) >0 || search("C198",[column],,0) >0,1, 0)

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi PhilipTreacy , it works!!
    Is it possible to standardized the problem code with description (Expected Output) as shown below?

    Problem CodeStandardized Problem CodeExpected Output
    Drawer won't open (C747) --BBBC747C747 - Drawer won't open
    Incorrect / Unexpected Results (C169) --DefaultC169C169 - Incorrect Unexpected esults
    Mixtures (e.g. Rack, Tray, Holders) (C163) --ComC163C163 - Mixtures (e.g. Rack, Tray, Holders)
    Cable / Wiring / Connector (C104) --DefaultC104C104 - Cable Wiring Connector onnector
    C110 CV'sC110C110 - CV's
    CV's (C110) --DefaultC110C110 - CV's
    Analysis Software (e.g. DiVA) (C150) --DefaultC150C150 - Analysis Software (e.g. DiVA)
    Sample (aspiration, dispense) (C186) --AC186C186 - Sample (aspiration, dispense)
    A&T / Setup (C816) --DefaultC816C816 - A&T / Setup
    Others (C200); describe specifics in CAUSE --DefaultC200C200 - Others
    C113 Electrical PowerC113C113 - Electrical Power
    Electrical Power (C113) --BBBC113C113 - Electrical Power
    Electrical Power (C113) --DefaultC113C113 - Electrical Power
  • Hi Anonymous 

    Yes. If you have a 2nd table with the Standardized Code and the Expected Output, you can join the 2 tables to get the result you want.

    Here's a sample PBIX showing this working

     

    If you don't want the middle column in the final table, just delete it.

    Regards

    Phil


    If I answered your question please mark my post as the solution.
    If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi PhilipTreacy , I don't have 2nd table with the Standardized Code and the Expected Output, but I wish to transform the "Problem Code" to "Expected Output". Is it possible?

       

      For example:

      Problem Code

      C110 CV's

      CV's (C110) --Default

      Ouput

      C110 - CV's

       

      Thanks.

  • Hi Anonymous 

    You'll have to create the table, that's how PBI/PQ will know what the output will look like.

    See this Excel workbook to illustrate what I mean.  I've created a tale with the Problem codes and another table with the Standardized Problem and expected Output.

    I don't know what your data source is but thisshows how to do it in Excel.

    You can also load or create a table in Power BI to do the same.

    Regards

    Phil


    If I answered your question please mark my post as the solution.
    If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi PhilipTreacy, I can't create the lookup table as I have more than 1000 cause code and problem code with different format in the table.

  • Hi Anonymous 

    Then there is no way to do what you want.  If you can't create a table to tell PBI/PQ what the expected output should be, it won't know what to do.

    Regards

    Phil