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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DECLARE statement in PBI using DirectQuery

Hi,

I'm using a direct query SQL in PBI. While using a DECLARE statement, it throws an error

 

Incorrect syntax near the keyqord 'DECLARE'. Incorrect syntax near ')'

 

My SQL statement is as follows:

DECLARE @effect_date as date;
Set @effect_date= (select distinct effective_date from in.input_table)

 

select * from abc

join ....

group by....

 

Any help is greatly appreciated.

3 REPLIES 3
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Can this query return data correctly in SSMS?

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
smpa01
Super User
Super User

@Anonymous can you try this

DECLARE @effect_date date= (select distinct effective_date from in.input_table)

 

select * from abc

join ....

group by....

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
amitchandak
Super User
Super User

@Anonymous , This you can use as sub query, Try that way

 

select * from abc

join ....

where date in (select distinct effective_date from in.input_table)

group by....

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors