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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
DmitryAD7
Helper I
Helper I

Custom Date Period

Hello community,

 

Please help, I need to create a table with custom periods:

Last 15 Months
Previous 15 Months

Years

 

I create all I needed in the calendar table:

 

Calendar = 
ADDCOLUMNS (
    CALENDAR ( DATE ( 2021, 1, 1 ), TODAY () ),
    "Year", FORMAT ( [Date], "yyyy" ),
    "Quarter", FORMAT ( [Date], "Q" ),
    "Month", FORMAT ( [Date], "mmm" ),
    "#Month", FORMAT ( [Date], "mm" ),
    "MonthYear", FORMAT ( [Date], "mmmm yyyy", "en-US" ),
    "Weekday", FORMAT ( [Date], "ddd" ),
    "#Weekday", FORMAT ( [Date], "w", "en-US" ) * 1000,
    "Day", FORMAT ( [Date], "dd" ),
    "Last 15 Months",
        IF (
            ( YEAR ( TODAY () ) - YEAR ( [Date] ) ) * 12
                + MONTH ( TODAY () )
                - MONTH ( [Date] ) + 1 <= 15,
            "Last 15 Months"
        ),
    "Previous 15 Months",
        IF (
            AND (
                ( YEAR ( TODAY () ) - YEAR ( [Date] ) ) * 12
                    + MONTH ( TODAY () )
                    - MONTH ( [Date] ) + 1 > 15,
                ( YEAR ( TODAY () ) - YEAR ( [Date] ) ) * 12
                    + MONTH ( TODAY () )
                    - MONTH ( [Date] ) + 1 <= 30
            ),
            "Previous 15 Months"
        )
)

 

But I can't get correct result in a custom table:

 

Custom Periods = 
UNION (
    ADDCOLUMNS (
        'Calendar',
        "Custom Period", 'Calendar'[Last 15 Months],
        "Sort", 1
    ),
    ADDCOLUMNS (
        'Calendar',
        "Custom Period", 'Calendar'[Previous 15 Months],
        "Sort", 2
    ),
    ADDCOLUMNS ( 'Calendar', "Custom Period", 'Calendar'[Year], "Sort", 3 )
)

 

I have blanks and unnecessary columns in a table . 

Screenshot 2024-05-09 185318.png 
pbix

1 ACCEPTED SOLUTION
xifeng_L
Super User
Super User

Hi @DmitryAD7 

 

Is this the result you want?

 

xifeng_L_0-1715329978964.png

 

If yes, you can use the below code:

 

Custom Periods = 
UNION (
    ADDCOLUMNS (
        FILTER('Calendar','Calendar'[Last 15 Months]<>BLANK()),
        "Custom Period", 'Calendar'[Last 15 Months],
        "Sort", 1
    ),
    ADDCOLUMNS (
        FILTER('Calendar','Calendar'[Previous 15 Months]<>BLANK()),
        "Custom Period", 'Calendar'[Previous 15 Months],
        "Sort", 2
    ),
    ADDCOLUMNS ( 'Calendar', "Custom Period", 'Calendar'[Year], "Sort", 3 )
)

 

 

View solution in original post

2 REPLIES 2
xifeng_L
Super User
Super User

Hi @DmitryAD7 

 

Is this the result you want?

 

xifeng_L_0-1715329978964.png

 

If yes, you can use the below code:

 

Custom Periods = 
UNION (
    ADDCOLUMNS (
        FILTER('Calendar','Calendar'[Last 15 Months]<>BLANK()),
        "Custom Period", 'Calendar'[Last 15 Months],
        "Sort", 1
    ),
    ADDCOLUMNS (
        FILTER('Calendar','Calendar'[Previous 15 Months]<>BLANK()),
        "Custom Period", 'Calendar'[Previous 15 Months],
        "Sort", 2
    ),
    ADDCOLUMNS ( 'Calendar', "Custom Period", 'Calendar'[Year], "Sort", 3 )
)

 

 

Anonymous
Not applicable

Hi @DmitryAD7 

 

I don't quite understand what your needs are, could you please show the result you want in excel form?  That would be very helpful. Thank you for your time and efforts in advance.

 

Best Regards,
Yulia Xu

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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