Forum Discussion

hongho2's avatar
hongho2
Frequent Visitor
2 years ago
Solved

power bi

Hi,   I have a date field that needs to be converted to nvarchar. In Power Query, I select the field and change the date type to text. How can I ensure that the time is not displayed from the field...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi hongho2 ,

    Please have a try.

    One way is to use the DateTime.ToText function, which returns a textual representation of a datetime value. You can specify the format and the culture of the output as optional parameters.

    = Table.TransformColumns(#“Previous Step”, {{“Date”, each DateTime.ToText(_, “MMM d yyyy”), type text}})

    This will transform the column “Date” from datetime to text, using the format “MMM d yyyy”.

    DateTime.ToText - PowerQuery M | Microsoft Learn

     

    Another way is to use the Date.ToText function, which returns a textual representation of a date value. This function is similar to DateTime.ToText, but it only works with date values, not datetime values.

    = Table.TransformColumns(#“Previous Step”, {{“Date”, each Date.ToText(_, “dd MMM yyyy”), type text}})

    This will transform the column “Date” from date to text, using the format “dd MMM yyyy”.

    Date.ToText - PowerQuery M | Microsoft Learn

     

    A third way is to use the Text.From function, which returns a textual representation of any value.

    = Table.TransformColumns(#“Previous Step”, {{“Date”, each Text.From(_), type text}})

    This will transform the column “Date” from any type to text, using the default format. 

    Solved: Converting specific text to date in PowerQuery - Microsoft Fabric Community

     

     

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Rongtie

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.