cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SuzieKidd
Regular Visitor

SQL to DAX

Hi, Can someone please help me, I need to write the following SQL in DAX 

 

DATEADD(s,-1,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)))

 

Thanks in advance

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @SuzieKidd ,

 

This is the correspondence between the sql function and the DAX function, please replace GETDATE() with today() or now().

vtangjiemsft_0-1675837122437.png

Please refer to the following document for more information.

DATEADD function (DAX) - DAX | Microsoft Learn

DATEDIFF function (DAX) - DAX | Microsoft Learn

 

Best Regards,

Neeko Tang

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

View solution in original post

2 REPLIES 2
v-tangjie-msft
Community Support
Community Support

Hi @SuzieKidd ,

 

This is the correspondence between the sql function and the DAX function, please replace GETDATE() with today() or now().

vtangjiemsft_0-1675837122437.png

Please refer to the following document for more information.

DATEADD function (DAX) - DAX | Microsoft Learn

DATEDIFF function (DAX) - DAX | Microsoft Learn

 

Best Regards,

Neeko Tang

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

amitchandak
Super User
Super User

@SuzieKidd , We have Datediff also in DAX.

 

But dateadd requires continuous dates

 

In case you need to subtract day , just do [mm] - 7

 

else use date as date add

 

https://community.powerbi.com/t5/Community-Blog/Date-as-Dateadd-Decoding-Date-and-Calendar-5-5-Power...



!! Microsoft Fabric !!
Microsoft Power BI Learning Resources, 2023 !!
Learn Power BI - Full Course with Dec-2022, with Window, Index, Offset, 100+ Topics !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!

Helpful resources

Announcements
May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Submit your Data Story

Data Stories Gallery

Share your Data Story with the Community in the Data Stories Gallery.

Top Solution Authors