Forum Discussion

kracrde's avatar
kracrde
Frequent Visitor
7 years ago
Solved

Question on data formatting

Hi all,

 

I have a problem with data formatting I am not able to resolve myself. I hope someone can give me a good hint on how to solve it.

I have a table with item numbers, description etc. The item numbers have unfortunately various formats (this is due to the bad data governance in our company). Some item numbers have 4,5 or 6 digits (e.g. 9718 or 78644). We also have special item numbers, e.g. 78644-0001 and M78644)

I have the article category group in a separate table and I would like to match them together with a relationship. The thing is, that I only have the category available for the first 5 digits, means 78644-0001  is not recognized and therefore no category is assigned to it.

I would like to format the item numbers in a way, that all the items with a -000X end are interpreted as 78644 only.

Is there a way to do it? I have come close to it by creating a separate column with only the first 5 digits, but items like M78644 are then not recognized.

 

Anyone an idea how to solve it?

 

  • Hi kracrde,

     

    You can model your data using the Query editor. As you have different cases in the data, some are having a delimiter '-' and some are starting with an alphabet. You need to apply the cleanup to all cases. Please see the video below that I created for you.

     

     

    If this helped you, please mark this post as an accepted solution and like to give KUDOS .

     

    Regards,

    Affan

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi,

     

    Can you try this formula for your calculated column?

     

     

    Item =
    IF (
        LEFT ( RIGHT ( Table1[ItemNumbers], 4 ), 3 ) = "000",
        LEFT ( Table1[ItemNumbers], 5 ),
        Table1[ItemNumbers]
    )

     

    Sample Output

     

    Original Item NumerItem
    M78644M78644
    78644-00178644
    7864478644
    78644-00578644

     

    This formula is only to test the logic as I have assumed that minimum there will be 5 characters. If you have items with length less than 5 characters, error will happen. You have to use IFERROR function to handle that error.

     

     

     

    • PattemManohar's avatar
      PattemManohar
      Community Champion

      kracrde If you want to do it in Power Query, please try "Custom Column" as below

       

      if Text.Start(Text.End([Value],5),4) = "-000" then "78644" else [Value]
    • kracrde's avatar
      kracrde
      Frequent Visitor

      hi sreenathv

       

      thank you for your quick reply. your formula has brought me a step further.

      The numbers are correctly formatted except all which have an ending -0010 and higher.

      All endings between -0001 and -0009 are fine.

       

      e.g. 78644-0001 to 78644-0009 are ok

      78644-0010 to 78644-9999 still show the -ending.

      • PattemManohar's avatar
        PattemManohar
        Community Champion

        kracrde Please try this in "Power Query Editor" by adding a "Custom Column"

         

        if Value.Is(Value.FromText(Text.End([Value],4)),type number) and Text.Start(Text.End([Value],5),1) = "-" then "78644" else [Value]

         

         

  • affan's avatar
    affan
    Solution Sage

    Hi kracrde,

     

    You can model your data using the Query editor. As you have different cases in the data, some are having a delimiter '-' and some are starting with an alphabet. You need to apply the cleanup to all cases. Please see the video below that I created for you.

     

     

    If this helped you, please mark this post as an accepted solution and like to give KUDOS .

     

    Regards,

    Affan