Forum Discussion

Judy101's avatar
Judy101
Frequent Visitor
1 year ago
Solved

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. 

  • 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.

5 Replies

  • 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.

  • 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.

     

  • v-ssriganesh's avatar
    v-ssriganesh
    Icon for Community Support rankCommunity 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.

  • v-ssriganesh's avatar
    v-ssriganesh
    Icon for Community Support rankCommunity 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's avatar
    v-ssriganesh
    Icon for Community Support rankCommunity 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.