Forum Discussion

Jaycena2024's avatar
Jaycena2024
Frequent Visitor
2 years ago
Solved

Importing multiple files from folders basis on current year vs last year

I have folders in the google drive named on a yearly basis from 2019 to 2024. Every year has folders in months (Jan - Dec) and every month folders has csv files (~7mb in size) date wise.  I want t...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Jaycena2024 ,

    Firstly I think you need to convert these file names into a date format that Power BI can recognize. This will allow you to perform date-based operations on them.

    Once you have the dates in a recognizable format, you can use Power BI's query editor to filter for the two specific dates you're interested in. You can use custom M code in the Advanced Editor to dynamically calculate the dates for "today" and the same day in the previous year. Here's a simplified example of how you might start to approach this:

    let
        Today = DateTime.LocalNow(),
        LastYear = Date.AddYears(Today, -1),
        FilteredRows = Table.SelectRows(YourTableName, each [YourDateColumn] = Today or [YourDateColumn] = LastYear)
    in
        FilteredRows

    Also you need to ensure that your Power BI report always selects the current date and its counterpart from the previous year without manual intervention, you'll want to incorporate dynamic date calculations. The M code snippet above demonstrates a basic approach to this by using DateTime.LocalNow() to always use the current date as part of the filter criteria.

     

     

    Best Regards

    Yilong Zhou

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.