Forum Discussion

ambi95's avatar
ambi95
Helper I
3 years ago

Excel formula to power query M code

Hi all, Im trying to convert the following formula in excel to M code :

=CONCATENATE(H2,
MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
IFERROR(IF(FIND(MID(H2,1,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0),0)
+IFERROR(IF(FIND(MID(H2,2,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0),0)

 

+IFERROR(IF(FIND(MID(H2,3,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0),0)
+IFERROR(IF(FIND(MID(H2,4,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0),0)
+IFERROR(IF(FIND(MID(H2,5,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0),0)
+1),1),
MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
IFERROR(IF(FIND(MID(H2,6,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0),0)
+IFERROR(IF(FIND(MID(H2,7,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0),0)
+IFERROR(IF(FIND(MID(H2,8,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0),0)
+IFERROR(IF(FIND(MID(H2,9,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0),0)
+IFERROR(IF(FIND(MID(H2,10,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0),0)
+1),1),
MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
IFERROR(IF(FIND(MID(H2,11,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0),0)
+IFERROR(IF(FIND(MID(H2,12,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0),0)

 

+IFERROR(IF(FIND(MID(H2,13,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0),0)
+IFERROR(IF(FIND(MID(H2,14,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0),0)
+IFERROR(IF(FIND(MID(H2,15,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0),0)
+1),1))

 

Assuming, H2 is a 15 digit string of mix of letters and numbers.

 

Please can you help me out with this.

12 Replies

  • ppm1's avatar
    ppm1
    Solution Sage

    I'm sure this can be done in the Power Query editor with Text.Split and list functions, but can you explain your logic? Also, your example value has only 13 characters.

     

    Pat

    • ambi95's avatar
      ambi95
      Helper I

      ppm thanks for the suggestion, could you tell me how ad where to start ?

      basically the logic is that we want to convert a 15 digit code to another 18 digit code - using that formula above

  • ppm1's avatar
    ppm1
    Solution Sage

    It looks like you are looking for the letters in your initial string. I put your formula into Excel. Can you exlpain how you get DAY suffix from that starting string (that only has two letters in it)?

     

     

    Pat

    • ambi95's avatar
      ambi95
      Helper I

      Hi ppm1 Apologies, I made a mistake in  my question. The original 15 digit string is a mix of letters and numbers.

      • ppm1's avatar
        ppm1
        Solution Sage

        Can you give an example of an input string with the expected output? The one shown isn't clear.

         

        Pat