Forum Discussion

carogomez's avatar
carogomez
Icon for Helper I rankHelper I
5 years ago
Solved

DAX in power query

HI!!

 

I`m having problems formulating in power bi query:

I want to add a column with 1 and 0, where 1 indicates the date is before from today and 0 if it is greated than today.

 

But there is an error and I don't understand why:

Can you tell me what i'm doing wrong?

Thanks

 

 

  • CNENFRNL's avatar
    CNENFRNL
    5 years ago

    carogomez , Power Query is also extremely strick with data type in calculation, if the column [fech] is of type Date, the formula should be what I wrote above; if DateTime, the formula should be this accordingly,

    if [fech]<=DateTime.LocalNow() then 1 else 0

7 Replies

  • CNENFRNL's avatar
    CNENFRNL
    Icon for Community Champion rankCommunity Champion

    Hi, carogomez , power query is case-sensitive and there's a specific way to obtain today's date. You might want to try this formula

    if [fech]<=DateTime.Date(DateTime.LocalNow()) then 1 else 0
    • carogomez's avatar
      carogomez
      Icon for Helper I rankHelper I

      Thank for your help. Now the formula is ok for power query but now their is an error in the columns:

       

       

  • carogomez 

    Check the Data Type of the following column, it has to be Date/Time, if not right-click and change it to Date/Time before adding the new column, also check if any error exists. 

    [fechainicio]

     

    ________________________

    If my answer was helpful, please click Accept it as the solution to help other members find it useful

    Click on the Thumbs-Up icon if you like this reply 🙂


    Website YouTube  LinkedIn 

    • carogomez's avatar
      carogomez
      Icon for Helper I rankHelper I

       

      "Fechainicio": I changed the column type to Date/time and the error persist. 

      What else is happenning, can`t understand.

      Thank you very much for your fast reply.

       

       

       

       

      • CNENFRNL's avatar
        CNENFRNL
        Icon for Community Champion rankCommunity Champion

        carogomez , Power Query is also extremely strick with data type in calculation, if the column [fech] is of type Date, the formula should be what I wrote above; if DateTime, the formula should be this accordingly,

        if [fech]<=DateTime.LocalNow() then 1 else 0
  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    FYI that you can click in the cell next to the word Error to see the error (not on the word).  In this case, you are comparing DateTime with Date which gives error.  You need to convert your column to Date first, or, if you need DateTime, you need to remove DateTime.Date from DateTime.LocalNow() or add DateTime.Date around your column.

     

    Regards,

    Pat