Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Learning PowerBI: Why do functions return "function" in a table, instead of actual "value"?

Ok... so I'm trying to learn the basics of Power BI, and I have a few points that are just down right confusing...

 

This isn't specific to DateTime, but I'm using it as a sample function...

 

If I run this code:

#"Renamed Columns2" = Table.AddColumn(#"Renamed Columns1", "Executed", each DateTime.LocalNow()),

The system returns a "Function" hyperlink in the Executed column.

 

However, if I run this code:

#"Renamed Columns2" = Table.AddColumn(#"Renamed Columns1", "Executed", each DateTime.Date(DateTime.LocalNow())),

The system returns the current date.

 

Question: DateTime.LocalNow(), as I understand, returns the local date when executed as a date value.  Why then do I have to use the additional DateTime.Date() to convert it from a "Function" hyperlink to the actual value.

 

 

  • Hi Anonymous ,

     

    I tried both scenarios in Power BI at my end.

    1. Created a custome column "test" using DateTime.LocalNow(). This gave me the current value in date-time format.
    2. Created a custom column "test1" usingDateTime.Date(DateTime.LocalNow()). This gave me the current value indate format.

             

     

    Just wanted to check if you can paste screenshot of the FUNCTION message which you are getting while using DateTime.LocalNow() as I don't get any such message at my end?

     

    If this helps and resolves the issue, appreciate a Kudos and mark it as a Solution! 🙂

     

    Thanks,

    Pragati

7 Replies

  • Hi Anonymous ,

     

    I tried both scenarios in Power BI at my end.

    1. Created a custome column "test" using DateTime.LocalNow(). This gave me the current value in date-time format.
    2. Created a custom column "test1" usingDateTime.Date(DateTime.LocalNow()). This gave me the current value indate format.

             

     

    Just wanted to check if you can paste screenshot of the FUNCTION message which you are getting while using DateTime.LocalNow() as I don't get any such message at my end?

     

    If this helps and resolves the issue, appreciate a Kudos and mark it as a Solution! 🙂

     

    Thanks,

    Pragati

    • RaphaelM's avatar
      RaphaelM
      New Member

      You were probably missing the " ( ) " at the end of the function.

      If you call  DateTime.LocalNow , the output is going to be Function

      If you call DateTime.LocalNow(), the output is going to be the real current date, for example, 2024-08-05.

      • JRD's avatar
        JRD
        Frequent Visitor

        Thanks! That's what i was doing wrong

  • Anonymous I don't know why you are getting function, DateTime.LocalNow() should return date/time (date with timestamp)

     

     

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

    • Anonymous's avatar
      Anonymous
      Not applicable

      parry2k, thank you for the response.  I should clarify I was doing this in Power Query / M, not DAX.  I'll see if I can grab a screenshot for you today.  Thank you for testing it out.

      • parry2k's avatar
        parry2k
        Super User

        Anonymous the sceenshot I shared is from power query not DAX.

  • v-xicai's avatar
    v-xicai
    Community Support

    Hi Anonymous ,

     

    The DateTime.LocalNow() returns a datetime value set to the current date and time on the system.. See more:https://docs.microsoft.com/en-us/powerquery-m/datetime-localnow.

     

    The DateTime.Date Convert DateTime format into Date format in Query Editor, see more: https://docs.microsoft.com/en-us/powerquery-m/datetime-date.

     

    Best Regards,

    Amy 

     

    Community Support Team _ Amy

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