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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Power Query to include 2 conditions with ‘and’ in Query string

Hi all: Good day! I am trying to pull 3 months old data [there is a parameter, 'endDate' that will start from 3 months from today and ends at yesterday]. I am trying to replace the hard coded static query string [1st Query string below] to a dynamic query [2nd Query string]

Query="select * from NatGas_V3.natgas.pipeline_maintenance_events#(lf)where endDate >='2020-08-23' and endDate<'2020-11-23' "

Query="select * from NatGas_V3.natgas.pipeline_maintenance_events#(lf)where endtDate >="  &ThreeMonthsEarlierFilter

 

I have  this query, ThreeMonthsEarlierFilter [Which returns ‘2020-08-23’ ]

= "'" & Date.ToText(Date.AddMonths(Date.From(DateTime.LocalNow()), -3),"yyyy-MM-dd") & "'"

I have another query [using to pull recent data], datefilter [returns today’s date]

= "'" & Date.ToText(Date.AddMonths(Date.From(DateTime.LocalNow()), -0),"yyyy-MM-dd") & "'"

 

My question is how do I use datefilter in the above dynamic Query string, not sure how to include the and clause and the end of query string “ to complete the Query! ☹

I would really appreciate help in this! Many thanks in advance! 🙂

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this string

 

Query="select * from NatGas_V3.natgas.pipeline_maintenance_events#(lf)where endtDate >="  &ThreeMonthsEarlierFilter & " and endDate < " & datefilter

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this string

 

Query="select * from NatGas_V3.natgas.pipeline_maintenance_events#(lf)where endtDate >="  &ThreeMonthsEarlierFilter & " and endDate < " & datefilter

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thanks a lot @mahoneypat for your prompt response! You did 'make my day'!🎶 Happy Thanksgiving to you all in US! 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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 Solution Authors