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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.