Results 1 to 1 of 1

Thread: PQ - Calendar with user defined StartDate and EndDate

  1. #1
    Sir Moderator sandy666's Avatar
    Join Date
    May 2018
    Posts
    239
    Rep Power
    7

    Cool PQ - Calendar with user defined StartDate and EndDate

    So, we will need one small Excel Table and two blank Queries

    Parameter
    Value
    StartDate
    29/07/2020
    EndDate
    31/07/2020

    in Name Manager change the name to Parameters

    first Query
    Code:
    (ParameterName as text) =>
        let
            ParamSource = Excel.CurrentWorkbook(){[Name="Parameters"]}[Content],
            ParamRow = Table.SelectRows(ParamSource, each ([Parameter]=ParameterName)),
                Value=
                if Table.IsEmpty(ParamRow)=true
                            then null
                            else Record.Field(ParamRow{0},"Value")
        in
            Value
    change the name to fnGetParameter

    second Query
    Code:
    let
        startdate = Number.From(fnGetParameter("StartDate")),
        enddate = Number.From(fnGetParameter("EndDate")), 
    
        Source = {startdate..enddate},
        ToTable = Table.FromList(Source, Splitter.SplitByNothing(), type table[Date = Date.Type], null, ExtraValues.Error),
        Type = Table.TransformColumnTypes(ToTable,{{"Date", type date}})
    in
        Type
    change the name to Calendar

    this is a basic calendar with dates column only but it can be extended to months, days, years, weeks and so on

    and extended result is

    Date Year Month Month Name Quarter Week of Year Week of Month Day Day of Week Day of Year Day Name
    29/07/2020
    2020
    7
    July
    3
    31
    5
    29
    2
    211
    Wednesday
    30/07/2020
    2020
    7
    July
    3
    31
    5
    30
    3
    212
    Thursday
    31/07/2020
    2020
    7
    July
    3
    31
    5
    31
    4
    213
    Friday
    Last edited by sandy666; 04-23-2023 at 12:49 AM.
    sandy
    I know you know but I forgot my Crystal Ball and don't know what you know also I may not remember what I did weeks, months or years ago so answer asap. Thinking doesn't hurt

Similar Threads

  1. UDF (user defined function) replacement for Excel's DATEDIF function
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 21
    Last Post: 03-07-2015, 09:47 PM
  2. Replies: 5
    Last Post: 06-13-2014, 08:37 PM
  3. Breaking the rules for UDF's (User Defined Functions)
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 6
    Last Post: 10-19-2013, 10:40 PM
  4. Replies: 2
    Last Post: 05-14-2013, 01:02 AM
  5. Excel Macro to Sort Data if a value changes in defined range
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 4
    Last Post: 09-05-2012, 10:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •