Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

IF/AND statement in query

Hi,

 

I want to create the count in query but this show syntax error.

Please help.

 

IF(MONTH([Created Date])=MONTH([Restoration Date]) &&
YEAR([Created Date])=YEAR([Restoration Date])),1,0)

 

  • Anonymous , The syntax you have give is DAX and you trying in power query.

     

    DAX

    IF(MONTH([Created Date])=MONTH([Restoration Date]) && YEAR([Created Date])=YEAR([Restoration Date]),1,0)

     

    Power Query /M

     

    if Date.Month([Created Date])=Date.Month([Restoration Date]) and Date.Year([Created Date])=Date.Year([Restoration Date]) then 1 else 0

    if Date.Month([Created Date])=Date.Month([Restoration Date]) && Date.Year([Created Date])=Date.Year([Restoration Date]) then 1 else 0

  • Hi,

    In the Query Editor, try this

    =if Date.Month([Created Date])=Date.Month([Restoration Date]) and Date.Year([Created Date])=Date.Year([Restoration Date]) then 1 else 0

    Hope this helps.

10 Replies

  • Anonymous , Try a new column like

    IF(MONTH([Created Date])=MONTH([Restoration Date]) && YEAR([Created Date])=YEAR([Restoration Date]),1,0)

  • Anonymous , a new column

    countrows(distinct(except(selectcolumns(filter(Table,Table[Category] ="B"), "ID", Table[ID]),selectcolumns(filter(Table,Table[Category] ="A"), "ID", Table[ID]))))

  • IF(MONTH([Created Date])=MONTH([Restoration Date]) &&
    YEAR([Created Date])=YEAR([Restoration Date]),1,0)
      • amitchandak's avatar
        amitchandak
        Super User

        Anonymous , The syntax you have give is DAX and you trying in power query.

         

        DAX

        IF(MONTH([Created Date])=MONTH([Restoration Date]) && YEAR([Created Date])=YEAR([Restoration Date]),1,0)

         

        Power Query /M

         

        if Date.Month([Created Date])=Date.Month([Restoration Date]) and Date.Year([Created Date])=Date.Year([Restoration Date]) then 1 else 0

        if Date.Month([Created Date])=Date.Month([Restoration Date]) && Date.Year([Created Date])=Date.Year([Restoration Date]) then 1 else 0

  • Anonymous's avatar
    Anonymous
    Not applicable

    hi Anonymous - try the below; I think you are missing a coupe of brackets

     

    IF( ( MONTH( [Created Date] )=MONTH( [Restoration Date] ) ) && ( YEAR([Created Date] )=YEAR( [Restoration Date] ) ), 1, 0)

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Anonymous ,

       

      It's not working.

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Anonymous 

         

        hi, if you are using Power Query to create the column then this is the syntax you should use: 

         

        if ( Date.Month([Date ID])=Date.Month([First Day of Month]) and Date.Year([Date ID])=Date.Year( [First Day of Month] )  ) then 1 else 0

         

        Note: the column names in the below screenshot are from my data model