Forum Discussion

WillemC's avatar
WillemC
Resolver I
9 years ago
Solved

dateadd function today minus period

Hi all,

 

I'm new to Power BI, but know my way around in SQL.

I'm trying to create a calculated column / measure with an if statement.

What I want to achieve is this:

 

if maxdate is larger than today - 3 months, then value 1 else value 0.

This should be very easy to do in my opnion

 

Column = if(Query1[maxdate]>dateadd(TODAY(),-3,MONTH),"1","0")

But I get the error: The first argument to DATEADD must specify a column.

Why isn't it possible to use today() ?

And how should I solve this?

(I tried it as a measure as well, but again to no avail.)

 

Could someone please help me?

I know I can solve it easily in my SQL query, but I want to understand why this doesn't work or how to solve this?

 

  • Table.Addcolumn needs a table parameter where you want to add the column. In my case the table is called '"Changed Type" which is the name of my last transformation step before Table.AddColumn.

     

    Your approach was just by using the button "custom column" So there you just write 

     

    if [EndDate]<Date.AddMonths(Date.From(DateTime.LocalNow()),-3) then 1 else 0)

    The rest will be added by Query Editor itself. 

  • So when you click on the word error he will show you some details about it.

     

    However

     

    You say that your date column is in datetime format? Could you please write Date.From([lastLD]) instead of [lastLD]

     

    Brackets are ok as far as i see

9 Replies

  • hi WillemC

     

    unfortunately it is different from sql language. In your case I would prefer Power Query to do the job.

     

    You can add a userdefined column

     

    • WillemC's avatar
      WillemC
      Resolver I

      okay, help me out a little bit.

      Where do I put this power query?

       

      I'm in the Query editor, under Add Column I see different types.

      Do I need a Custom Column or Conditional Column? Or something else?

       

      The query itself is clear to me.

       

      • spuder's avatar
        spuder
        Resolver IV

        custom column

         

        all other options are in fact custom columns as well. But they help you to get your wishes without writing code.

         

        (conditional e.g. is the click variant of if then else)