Forum Discussion

spandy34's avatar
spandy34
Responsive Resident
2 years ago
Solved

DAX Month Date Table

How would I create a date table in Dax that lists the start date and end date of each month from 01/07/2007 to 31/12/2099 similar to the format below?  Thank you in advance     amitchandak t...
  • tamerj1's avatar
    2 years ago

    Hi spandy34 

    please try

    Month Date =
    VAR MinDate =
    DATE ( 2007, 7, 1 )
    VAR MaxDate =
    DATE ( 2099, 12, 31 )
    VAR Months =
    DATEDIFF ( MinDate, MaxDate, MONTH )
    VAR T1 =
    GENERATESERIES ( 0, Months, 1 )
    RETURN
    SELECTCOLUMNS (
    T,
    "StartDate", EDATE ( Mindate, [Value] ),
    "EndDate", EOMONTH ( MinDate, [Value] )
    )

  • tamerj1's avatar
    tamerj1
    2 years ago

    spandy34 

    Sorry its a typo in the variable name

    Month Date =
    VAR MinDate =
    DATE ( 2007, 7, 1 )
    VAR MaxDate =
    DATE ( 2099, 12, 31 )
    VAR Months =
    DATEDIFF ( MinDate, MaxDate, MONTH )
    VAR T =
    GENERATESERIES ( 0, Months, 1 )
    RETURN
    SELECTCOLUMNS (
    T,
    "StartDate", EDATE ( Mindate, [Value] ),
    "EndDate", EOMONTH ( MinDate, [Value] )
    )

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi  spandy34 ,

     

    Here are the steps you can follow:

    1. Create calculated table.

    Table =
    var _table1=
    CALENDAR(
        DATE(2007,1,1),
        DATE(2099,12,31))
    var _table2=
    ADDCOLUMNS(
        _table1,"Enddate",EOMONTH([Date],0))
    return
    FILTER(
        _table2,   [Date]=MINX(FILTER(_table2,YEAR([Date])=YEAR(EARLIER([Date]))&&MONTH([Date])=MONTH(EARLIER([Date]))),[Date]))

    2. Result:

     

     

    Best Regards,

    Liu Yang

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

  • tamerj1's avatar
    2 years ago

    spandy34 
    Please refer to attached sample file with the solution

    Month Date = 
    VAR MinDate =
        DATE ( 2007, 7, 1 )
    VAR MaxDate =
        DATE ( 2099, 12, 31 )
    VAR Months =
        DATEDIFF ( MinDate, MaxDate, MONTH )
    VAR T =
        GENERATESERIES ( 0, Months, 1 )
    RETURN
        SELECTCOLUMNS (
            T,
            "StartDate", EDATE ( Mindate, [Value] ),
            "EndDate", EOMONTH ( MinDate, [Value] )
        )