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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Daniel_Lima_Car
New Member

Get correct file in the folder

Hi folks!

 

I have an API that gives me one file per day with all ticket information of the month, so, on day 1 I have only records for 1 day, and day 30 I have all tickets of the month.

 

I have a dashboard that I need to get the last file of the previous month and the last of the current month.

 

Daniel_Lima_Car_0-1685732796340.png

 

In the example, I need to filter the 02/06 file and the 31/05 file, and next month will be 01/07, 30/06 and 31/05 and so on.

 

If I were in a SQL environment I probably solved this by adding a rank column with PARTITION BY (MONTH, DAY) ORDER BY (MONTH, DAY DESC).

 

How to do this in PowerQuery?

 

Any ideas?

 

Tks a lot!

1 ACCEPTED SOLUTION
Daniel_Lima_Car
New Member

Hi folks!


I've got what I wanted this way:

 

1. Orderd the data from "Date"

2. Created a column with rank (0..N)

3. Created a condicional column that check if the file date is the last of the month OR rank = 0

4. Filtered true columns 

  #"Personalização Adicionada1" = Table.AddColumn(#"Colunas Renomeadas3", "LastDayMonthOrFirstLine", each if [Date created] = Date.EndOfMonth([Date created]) or [Rank] = 0  then  100 else  0)

 

Tks for the helping! 

View solution in original post

3 REPLIES 3
Daniel_Lima_Car
New Member

Hi folks!


I've got what I wanted this way:

 

1. Orderd the data from "Date"

2. Created a column with rank (0..N)

3. Created a condicional column that check if the file date is the last of the month OR rank = 0

4. Filtered true columns 

  #"Personalização Adicionada1" = Table.AddColumn(#"Colunas Renomeadas3", "LastDayMonthOrFirstLine", each if [Date created] = Date.EndOfMonth([Date created]) or [Rank] = 0  then  100 else  0)

 

Tks for the helping! 

vanessafvg
Super User
Super User

as an example you do something like this and then the inverse with min for the other, create 2 queries  one for min and one for max and then append them?

 

let

Source = Folder.Files("D:\OneDrive - foldername\Data"),
#"Filtered Rows" = Table.SelectRows(Source, let latest = List.Max(Source[Date modified]) in each [Date created] = latest)

in
#"Filtered Rows"





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Tks for aswering!

 

I've tried that but, my issue here is that each month I need to pick the last file, it worked for the first two months, then it fails, because it's not the first and last only... is the first and like 5 last files of old months...

 

Tks!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.