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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Judy101
Frequent Visitor

Subset of dates from a table using Power query

Looking for Power query that helps list dates in a table from a pre-exisiting table.

Conditions:

1. Minimum date should be 1st date of data from 26 months back. Example if today is 3/25/2025, I want the minimum date to be 2/1/2023.

2. 

1 ACCEPTED SOLUTION
pankajnamekar25
Memorable Member
Memorable Member

Hello Judy,

 

You can try below M script

 

let

    Today = Date.From(DateTime.LocalNow()),

        StartDate = Date.StartOfMonth(Date.AddMonths(Today, -26)),

    DateList = List.Dates(StartDate, Duration.Days(Today - StartDate) + 1, #duration(1,0,0,0)),

    DateTable = Table.FromList(DateList, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error)

in

    DateTable

 

Thanks,
Pankaj

If this solution helps, please accept it and give a kudos, it would be greatly appreciated.

View solution in original post

5 REPLIES 5
v-ssriganesh
Community Support
Community Support

Hi @Judy101,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.

v-ssriganesh
Community Support
Community Support

Hi @Judy101,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

v-ssriganesh
Community Support
Community Support

Hi @Judy101,

Thank you for posting your query in the Microsoft Fabric Community Forum, and thanks to @pankajnamekar25 & @danextian for sharing valuable insights.

Could you please confirm if your query has been resolved with the solutions provided? If they have, kindly mark the helpful response and accept it as the solution. This will assist other community members in resolving similar issues more efficiently.

Thank you.

danextian
Super User
Super User

Hi @Judy101 

 

Try this:

let
    //get today's date relative to the user's timezone. Note: PBI Service uses UTC
    TodaysDate = Date.From(DateTime.From(DateTimeZone.RemoveZone(DateTimeZone.UtcNow()) + #duration(0,8,0,0))),
    StartDate = Date.AddMonths(TodaysDate,-26),
    //creates a list of numbers from the number of equivalent of StartDate to TodaysDate and then transform the list to dates
    Dates = List.Transform( {Number.From(StartDate)..Number.From(TodaysDate)}, Date.From),
    #"Converted to Table" = Table.FromList(Dates, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Date", type date}})
in
    #"Changed Type"

This takes into consideration that user's machine's timezone is different from that of PBI Service.

danextian_0-1742904176447.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
pankajnamekar25
Memorable Member
Memorable Member

Hello Judy,

 

You can try below M script

 

let

    Today = Date.From(DateTime.LocalNow()),

        StartDate = Date.StartOfMonth(Date.AddMonths(Today, -26)),

    DateList = List.Dates(StartDate, Duration.Days(Today - StartDate) + 1, #duration(1,0,0,0)),

    DateTable = Table.FromList(DateList, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error)

in

    DateTable

 

Thanks,
Pankaj

If this solution helps, please accept it and give a kudos, it would be greatly appreciated.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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