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

Power Query Declare

Hello all, 

 

I know this has been asked and i attempted to fix however i can not for the life of me figure out how to have a dynamic date DECLARE in my sql and transfer that to the power query. This is a live connection with direct query and i can not create views as i do not own the db. 

 

The query (works in sql and populates in preview)

 
 
DECLARE @today DATE =GETDATE()
DECLARE @yest DATE = CAST(GETDATE() -1 AS date);
select *
from dbo.CDRMAIN
where CAST([LocalDay] as varcharBETWEEN @yest and @today 
and [TargetWGNum] = 381
 
Any help will be greatly appreciated. 
1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Power Query Declare

Hi @cking2019 , 

You could use below query directly in powerbi like below

580.PNG

select *
from dt
where d BETWEEN CAST(GETDATE() -1 AS date) and GETDATE()

Or you also could refer to Pass parameter to SQL Queries statement using Power BI  for details.

Best Regards,
Zoe Zhi

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

1 REPLY 1
Community Support
Community Support

Re: Power Query Declare

Hi @cking2019 , 

You could use below query directly in powerbi like below

580.PNG

select *
from dt
where d BETWEEN CAST(GETDATE() -1 AS date) and GETDATE()

Or you also could refer to Pass parameter to SQL Queries statement using Power BI  for details.

Best Regards,
Zoe Zhi

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

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Top Solution Authors
Top Kudoed Authors