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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
dadb25
Helper I
Helper I

Sort files by month

Hi Community,

 

I use data in a Sharepoint folder, where 3 news files are automatically stored every days.

dadb25_0-1706003554442.png

 

I want to sort them, to keep the 3 earliest files (sorted by column modified).

For the current month, I know how to do it, but how can I sort these files for every months ?

Meaning, I need the 3 last files for January, for December and so on ... ?

Thank you

Regards

1 ACCEPTED SOLUTION

Essaye cela dans ton code, 

let
    Source = Ta Source SharePoint,
    AddYear = Table.AddColumn(Source, "Year", each Date.Year([Date modified]), type number),
    AddYearMonth = Table.AddColumn(AddYear, "Month", each Date.Month([Date modified]), type number),
    SortedFiles = Table.Sort(AddYearMonth, {{"Date modified", Order.Descending}}),
    GroupedFiles = Table.Group(SortedFiles, {"Year", "Month"}, {
        {"AllData", each _, type table}}),
    AddIndexAndFilter = Table.TransformColumns(GroupedFiles, {
        "AllData", each Table.FirstN(Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type), 3)
    })
in 

AddIndexAndFilter

 

Ensuite tu developpes la colonne Data et tu gardes les colonnes que tu veux

View solution in original post

4 REPLIES 4
Einomi
Helper V
Helper V

Hi @dadb25 

So you want the 3 most recent files for every month ?

Hi @Einomi 

Yes, that's what I need 😁

Essaye cela dans ton code, 

let
    Source = Ta Source SharePoint,
    AddYear = Table.AddColumn(Source, "Year", each Date.Year([Date modified]), type number),
    AddYearMonth = Table.AddColumn(AddYear, "Month", each Date.Month([Date modified]), type number),
    SortedFiles = Table.Sort(AddYearMonth, {{"Date modified", Order.Descending}}),
    GroupedFiles = Table.Group(SortedFiles, {"Year", "Month"}, {
        {"AllData", each _, type table}}),
    AddIndexAndFilter = Table.TransformColumns(GroupedFiles, {
        "AllData", each Table.FirstN(Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type), 3)
    })
in 

AddIndexAndFilter

 

Ensuite tu developpes la colonne Data et tu gardes les colonnes que tu veux

Merci beaucoup, c'est parfait 😁

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors