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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

List of dates from range and schedule

I have a table of Deals with following fields:

  • period_start = DATE
  • period_end = DATE
  • schedule = Number of Months

Now I need to create the table of invoices, with the date column:

  • if schedule is "monthly", I want to get one column with period_start date, and following rows with dates incremented by 1 month but not exceeding period_end date
2 ACCEPTED SOLUTIONS
v-shex-msft
Community Support
Community Support

HI @Anonymous,

 

It is possible to generate a table with specific increase date, but it is impossible to make it dynamic based on slicer or filters.


Sample:

Expand =
VAR _start =
    DATE ( 2015, 1, 1 )
VAR _end =
    TODAY ()
VAR _calendar =
    CALENDAR ( _start, _end )
VAR temp =
    SELECTCOLUMNS (
        { ( DATE ( 2015, 1, 1 ), TODAY () ) },
        "StartDate", [Value1],
        "EndDate", [Value2]
    )
VAR interval = 2
RETURN
    DISTINCT (
        SELECTCOLUMNS (
            FILTER (
                ADDCOLUMNS (
                    CROSSJOIN ( temp, _calendar ),
                    "Rolling Date", DATE ( YEAR ( [StartDate] ), MONTH ( [StartDate] )
                        + interval * DATEDIFF ( [StartDate], [Date], MONTH ), DAY ( [StartDate] ) )
                ),
                [Rolling Date] <= [EndDate]
            ),
            "Start Date", [StartDate],
            "End Date", [EndDate],
            "Rolling Date", [Rolling Date]
        )
    )

5.PNG

 

Notice: Bold part is modicatable.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

You could also do this in the query editor: https://www.thebiccountant.com/2017/12/11/date-datesbetween-retrieve-dates-between-2-dates-power-bi-...

 

Copy the code into the advanced editor of an empty query and name it "fnDatesBetween".

Then add a column to your table where you call the function and reference the relevant columns like so:

 

fnDatesBetween([StartDate], [EndDate], "Month")

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @Anonymous,

 

It is possible to generate a table with specific increase date, but it is impossible to make it dynamic based on slicer or filters.


Sample:

Expand =
VAR _start =
    DATE ( 2015, 1, 1 )
VAR _end =
    TODAY ()
VAR _calendar =
    CALENDAR ( _start, _end )
VAR temp =
    SELECTCOLUMNS (
        { ( DATE ( 2015, 1, 1 ), TODAY () ) },
        "StartDate", [Value1],
        "EndDate", [Value2]
    )
VAR interval = 2
RETURN
    DISTINCT (
        SELECTCOLUMNS (
            FILTER (
                ADDCOLUMNS (
                    CROSSJOIN ( temp, _calendar ),
                    "Rolling Date", DATE ( YEAR ( [StartDate] ), MONTH ( [StartDate] )
                        + interval * DATEDIFF ( [StartDate], [Date], MONTH ), DAY ( [StartDate] ) )
                ),
                [Rolling Date] <= [EndDate]
            ),
            "Start Date", [StartDate],
            "End Date", [EndDate],
            "Rolling Date", [Rolling Date]
        )
    )

5.PNG

 

Notice: Bold part is modicatable.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

You could also do this in the query editor: https://www.thebiccountant.com/2017/12/11/date-datesbetween-retrieve-dates-between-2-dates-power-bi-...

 

Copy the code into the advanced editor of an empty query and name it "fnDatesBetween".

Then add a column to your table where you call the function and reference the relevant columns like so:

 

fnDatesBetween([StartDate], [EndDate], "Month")

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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