PowerQuery pull back selected date

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi All

I have set up powerQuery connection to pull back data from a database - At the minute it pulls back everything

Is it possible to only pull back data from a start date and end date in excel?

so say im A1 i have startdate and A2 i have enddate - Can i only pull back that data so im not pulling more data than needed?

And also in VBA - im refreshing all the powerQuery connections...I recorded a macro and the macro code first selects the sheet and then uses Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False

I tried to not use the select method and just refresh it by using the following thisworkbook.connections(“tblQuery”).refresh but that fails
how can i avoid using select?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
in short:
1. use startdate and enddate to generate all dates in this range then merge this column with your database by date column
2. maybe this
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim con As WorkbookConnection
Dim Cname As String

For Each con In ActiveWorkbook.Connections
    If Left(con.Name, 8) = "Query - " Then
    Cname = con.Name
        With ActiveWorkbook.Connections(Cname).OLEDBConnection
            .BackgroundQuery = False  'or true, up to you
            .Refresh
        End With
    End If
Next
End Sub
 
Upvote 0
in short:
1. use startdate and enddate to generate all dates in this range then merge this column with your database by date column
2. maybe this
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim con As WorkbookConnection
Dim Cname As String

For Each con In ActiveWorkbook.Connections
    If Left(con.Name, 8) = "Query - " Then
    Cname = con.Name
        With ActiveWorkbook.Connections(Cname).OLEDBConnection
            .BackgroundQuery = False  'or true, up to you
            .Refresh
        End With
    End If
Next
End Sub

thank you

sorry not sure what and the steps to the point1..I’m new to power query so apologies
 
Upvote 0
Can that start date and end date reference cells in excel?

mans then how do I only pull back or keep dates that fall within the date range
 
Upvote 0
Thank you - I’ll give that a go - how can I then use this to only pull back Data or keep dates that are found within that range so only pull back limited data
 
Upvote 0
in this file you've defined range of dates
you need to add source from database where you've column with dates (probably)
merge these tables by date columns Left Outer and it will give you records for defined dates
then remove not necessary column(s) and transform table as you wish
 
Upvote 0
Sorry Mate, only just seen that you had responded back - Thank you

If im understanding your logic...

Am i right in saying i need to do these steps to pull back selected data (It was so much easier with older version imo)

1) A1: Enter Start Date
2) B1: Enter End Date
3) Generate a list of dates in Excel between those 2 dates (say this table is called DateList)
4) Get data from database
5 Get data from Excel
6) Join date table to database date

Now how do i do a left outer join in PowerQuery?

In older query option - you can put start and end date from cell and load straight back - i wonder why they took that out
 
Upvote 0

Forum statistics

Threads
1,214,605
Messages
6,120,476
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top