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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
tkconsultingnl
Frequent Visitor

How to Dynamic date period

Hi PBI Expert,

 

I am working with different mesaures,  I would like to have year, month, dynamic mesaures created. I have a table with various data, but I don't want to be selecting runperiod manually I would like to automate the year and month to show the following in the table:

1. Current Period

2. Previous Month.

3. Previous quater

4. Previous year.

 

How can I combine all 4 togther in DAX, that when data is been uploaded when I refreshed the repor it should populate the data.

 

Thanks in davance 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @tkconsultingnl ,

 

May I ask what range of dates the Current Period specifically refers to? I use it as the current month to do the following steps: 1. Create a new table with all the options you need in the slicer.

vjianbolimsft_0-1656312710026.png

 2. Turn the single select of the slicer on

vjianbolimsft_1-1656312710030.png

3. Then create a measure that filters the date period.

 

Measure =

SWITCH (

    MAX ( 'For Slicer'[Value] ),

    "Current Period", IF ( DATEDIFF ( MAX ( 'Table'[Date] ), TODAY (), MONTH ) = 0, 1, 0 ),

    "Previous Month", IF ( DATEDIFF ( MAX ( 'Table'[Date] ), TODAY (), MONTH ) = 1, 1, 0 ),

    "Previous Quarter",

        VAR currYearQua =

            YEAR ( TODAY () ) * 100

                + QUARTER ( TODAY () )

        VAR yearQua =

            YEAR ( MAX ( 'Table'[Date] ) ) * 100

                + QUARTER ( MAX ( 'Table'[Date] ) )

        RETURN

            IF ( currYearQua - yearQua = 1 || currYearQua - yearQua = 97, 1, 0 ),

    "Previous Year",

        IF ( YEAR ( MAX ( 'Table'[Date] ) ) = YEAR ( TODAY () ) - 1, 1, 0 )

 

4. Apply the measure to the visual - level filter , set "is 1":

   Final output:

vjianbolimsft_2-1656312710033.png

 

vjianbolimsft_3-1656312710036.png

 

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Jianbo Li

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

View solution in original post

2 REPLIES 2
v-jianboli-msft
Community Support
Community Support

Hi @tkconsultingnl ,

 

May I ask what range of dates the Current Period specifically refers to? I use it as the current month to do the following steps: 1. Create a new table with all the options you need in the slicer.

vjianbolimsft_0-1656312710026.png

 2. Turn the single select of the slicer on

vjianbolimsft_1-1656312710030.png

3. Then create a measure that filters the date period.

 

Measure =

SWITCH (

    MAX ( 'For Slicer'[Value] ),

    "Current Period", IF ( DATEDIFF ( MAX ( 'Table'[Date] ), TODAY (), MONTH ) = 0, 1, 0 ),

    "Previous Month", IF ( DATEDIFF ( MAX ( 'Table'[Date] ), TODAY (), MONTH ) = 1, 1, 0 ),

    "Previous Quarter",

        VAR currYearQua =

            YEAR ( TODAY () ) * 100

                + QUARTER ( TODAY () )

        VAR yearQua =

            YEAR ( MAX ( 'Table'[Date] ) ) * 100

                + QUARTER ( MAX ( 'Table'[Date] ) )

        RETURN

            IF ( currYearQua - yearQua = 1 || currYearQua - yearQua = 97, 1, 0 ),

    "Previous Year",

        IF ( YEAR ( MAX ( 'Table'[Date] ) ) = YEAR ( TODAY () ) - 1, 1, 0 )

 

4. Apply the measure to the visual - level filter , set "is 1":

   Final output:

vjianbolimsft_2-1656312710033.png

 

vjianbolimsft_3-1656312710036.png

 

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Jianbo Li

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

Hi v-jianboili,

 

Thanks for your heads up on this.

 

The current period refers to the actual month the data is availabe, so if May data was loaded and June data not available yet it should still show for the May.

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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