Filter imported data through Power Query

Dimuster

New Member
Joined
Jan 16, 2023
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
Hi.

I have my Solar generation data exported to excel files which have records throughout the day in 5 minutes intervals. Excel files break in days wise by the solar data software & stored in a folder.

For analyzing & report creation purposes I import these files to an excel through Power query. Sometimes I want to get a particular day's data into an excel sheet. @Peter_SSs gave me a suggestion to extract the required date's data if I have all data in the excel sheet. But rather than importing all the data to an Excel sheet & then filtering, I want to filter the data inside the power query & import only the required data to the excel sheet.

In the excel sheet I have a cell in that I input the date I want. Then I want to power query to read that date & filter only the data that match to the said date & import to the excel sheet.

Please help me to have this done.

I have Office Professional Plus 2019 version in Excel.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
When you open the query, it will look just like an Excel table. You can manually filter the data the same way, and the M Code will be generated automatically, but it will not be dynamic and can only be changed by editing the query.
Alternatively you can create a table of exclusions and then filter out those entries from the column of the table that needs the filtering.
Book1
ABCDE
1Full NameExcludeFull Name
2Darion EvelynMadyson HamptonDarion Evelyn
3Marina EvansLyric LeycesterMarina Evans
4Madyson HamptonMeghan Tefft
5Meghan TefftKali Armitage
6Adrianna ChatseyKaley Jenkins
7Kali ArmitageAbram Alarcón
8Kaley JenkinsArabella Azevedo
9Abram AlarcónCharity Mayo
10Lyric LeycesterZain Kingston
11Arabella AzevedoCasey Clowes
12Charity MayoTerrence Colburn
13Zain KingstonPrince Calder
14Casey ClowesKayli Russell
15Terrence ColburnPierce Jensen
16Enzo Andreassen
17Prince Calder
18Kayli Russell
19Pierce Jensen
Sheet1

The table on the left is named Names. The table in the middle is named Exclude.
Bring the Exclude table into Power Query and convert it to a list by right clicking on the column and select Drill Down:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Exclude"]}[Content],
    DrillDown = Source[Exclude]
in
    DrillDown
Steps are manually renamed. I hate that #"" nonsense!
Now pull in the data file. I've included one step using a manual filter, and one using the Exclude list:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Names"]}[Content],
    FilteredSelectedRows = Table.SelectRows(Source, each ([Full Name] <> "Adrianna Chatsey" and [Full Name] <> "Enzo Andreassen")),
    FilteredByList = Table.SelectRows(FilteredSelectedRows, each ( List.Contains( Exclude, [Full Name] ) = false  ))
in
    FilteredByList
You end up with the table on the right. Either way, you should be set.
 
Upvote 0
Thanks for the answer. But I want to extract the data that match the date. Not to Exclude.

Sorry if I misunderstood.
 
Upvote 0
With D2 being a named Range name Date_To_Import,

Power Query:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(
        "fZFLCoAwDAWvIl0L5qUfrTsPIHQv3v8aFsViQyJ0N0wnIcfhMAETE/sBvBLVN2y7G12GO8cvTl8KigI3u9x2NuyH8ktZS4MWwUU7WXrp
        J2elDWrYq3vPAnftHCzZ+Fy0/YuDujhIcCMu7SJuEtR4w/H/4FFre0su/WhRu3c92HkB", 
        BinaryEncoding.Base64), Compression.Deflate)), type table [#"Date/Time", Output]),
    tbl = Table.TransformColumnTypes(Source,{{"Date/Time", type datetime}, {"Output", type number}}),
    dt = Date.From(Excel.CurrentWorkbook(){[Name = "Date_To_Import"]}[Content][Column1]{0}),
    Result = Table.SelectRows(tbl, each Date.From([#"Date/Time"]) = dt)
in
    Result

Book4
ABCDE
1Date/TimeOutputDate To Import
21/14/2023 0:001101/14/2023
31/14/2023 6:0094
41/14/2023 12:00105
51/14/2023 18:00105
6
Table
 
Upvote 0

Forum statistics

Threads
1,223,391
Messages
6,171,815
Members
452,426
Latest member
cmachael

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