Forum Discussion

Ocasio27's avatar
Ocasio27
Iron Contributor
Feb 10, 2020
Solved

Concatenate dates

Hello everyone. 

 

When I try to concatenate 3 columns, one of them has dates, I get in the results column a number that equales a date. Very annoying.

 

My column formula

=CONCAT([@[Name]],"-",[@[Record _number]],"-",[@[Expiration_Date]])

 

Example Result:

John Smith-033111-43706

 

What I really want:

John Smith-033111-08/29/2019

 

Any help on this? Thanks in advance

  • Ocasio27 

    In DAX

    you may use

    =CONCATENATE(Table1[Name],CONCATENATE("-",CONCATENATE(Table1[Record Number],CONCATENATE("-",Table1[Expiration Date]))))

    but much better is

    =Table1[Name] & "-" & Table1[Record Number] & "-" & Table1[Expiration Date]

9 Replies

  • Ocasio27's avatar
    Ocasio27
    Iron Contributor

    Ocasio27 

    I am now trying to do this in a Power Pivot table, it does not accept more than 2 arguments. How can I do this in power pivot.

    • SergeiBaklan's avatar
      SergeiBaklan
      Diamond Contributor

      Ocasio27 

      In DAX

      you may use

      =CONCATENATE(Table1[Name],CONCATENATE("-",CONCATENATE(Table1[Record Number],CONCATENATE("-",Table1[Expiration Date]))))

      but much better is

      =Table1[Name] & "-" & Table1[Record Number] & "-" & Table1[Expiration Date]

  • Ocasio27 

     

    In addition, you can use flash fill (programming by example)

    1. Type in the values in each of the three columns and separate with - 

    2. Click Enter

    3. Execute CTRL + 3.

     

    This is much faster

     

     

    • Ocasio27's avatar
      Ocasio27
      Iron Contributor

      Riny_van_Eekelen 

       

      =CONCAT([@Name],"-",[@Record_number],"-",TEXT([@Expiration_Date],"dd/mm/yyyy"))

       

      =CONCAT([@[Name]],"-",[@Record_number],"-",TEXT([@[Expiration_Date]],"dd/mm/yyyy"))

       

      Made a slight modification. For some reason I MUST keep the first and last columns with [@[]] or else i get a mess, IDK why

      • Riny_van_Eekelen's avatar
        Riny_van_Eekelen
        Platinum Contributor

        Ocasio27 

        What's "IDK"?

        I replicated your example as shown in the picture below. Don't understand why you must have the extra

        "[@[]]". But if it works for you, that's okay, I guess.

  • Ocasio27 

    The best way to achieve your desired outcome is as follows

    1. Click anywhere in your data and press CTRL + T. Ensure my data has headers is checked. 

    2. Click OK

    3. In the Data tab, click on From Table/Range

    4. In the Power Query editor, select all the three columns 

    5. Click on Merge Columns in the Add Column tab

    6. In the Merger Column dialogue box, select Custom as Separator

    7. In the box below, type in - (as your separator)

    8. Click OK

    In the caption below, you have the newly added column

     

    9. Right-click on the first 3 columns and select Remove columns

    10. Finally, select Close and Load in the Home tab to load the result back to Excel 

    That is the final answer.

     

     

    TEXTJOIN method

     

     
     
     

    =TEXTJOIN("-",TRUE,D5,E5,TEXT(F5,"mm/dd/yyyy"))

    See attached

     

    If this solve your question, kindly do accept as the Best Response.

     

     

    Regards

     

     

     

Resources