Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
cking2019
Frequent 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
dax
Community Support
Community Support

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
dax
Community Support
Community Support

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.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors