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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
PrivateAnalytic
Helper IV
Helper IV

Dynamic Date Key

Good morning all! Is it possible I can create a dynamic date column in a table from this Date - Month column depicted below? Ideally, I would like the most recent date, in this case Sep 2022 to have a value of 1, and the months prior to keep countining upwards. But after every new updated month, I always want the most recent month to be 1. 

PrivateAnalytic_0-1665493574710.png

 

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

Hi @PrivateAnalytic ,

 

You can try this method:

The year and month of the date in the table are calculated first:

vyinliwmsft_0-1665654029982.png

vyinliwmsft_1-1665654053859.png

The year and month of the current date are then calculated:

vyinliwmsft_2-1665654091477.png

vyinliwmsft_4-1665654125724.png

The difference between the months is then calculated:

 

Column:

Number =
IF (
    'Sample Table'[Table Data Month] < 'Sample Table'[Current Month],
    'Sample Table'[Current Month] - 'Sample Table'[Table Data Month] + ( 'Sample Table'[Current Year] - 'Sample Table'[Table Data Year] ) * 12,
    ( 'Sample Table'[Current Year] - 'Sample Table'[Table Data Year] ) * 12 - ( 'Sample Table'[Table Data Month] - 'Sample Table'[Current Month] )
)

 

vyinliwmsft_5-1665654245888.png

Then use the year and month of the data in the table as a filter, use the card visual, introduce the number column, and you can view it:

vyinliwmsft_6-1665654339544.png

vyinliwmsft_8-1665654372249.png

 

 

Is this the result you would expect?

 

Hope this helps you.

 

Best Regards,

Community Support Team _Yinliw

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-yinliw-msft
Community Support
Community Support

Hi @PrivateAnalytic ,

 

You can try this method:

The year and month of the date in the table are calculated first:

vyinliwmsft_0-1665654029982.png

vyinliwmsft_1-1665654053859.png

The year and month of the current date are then calculated:

vyinliwmsft_2-1665654091477.png

vyinliwmsft_4-1665654125724.png

The difference between the months is then calculated:

 

Column:

Number =
IF (
    'Sample Table'[Table Data Month] < 'Sample Table'[Current Month],
    'Sample Table'[Current Month] - 'Sample Table'[Table Data Month] + ( 'Sample Table'[Current Year] - 'Sample Table'[Table Data Year] ) * 12,
    ( 'Sample Table'[Current Year] - 'Sample Table'[Table Data Year] ) * 12 - ( 'Sample Table'[Table Data Month] - 'Sample Table'[Current Month] )
)

 

vyinliwmsft_5-1665654245888.png

Then use the year and month of the data in the table as a filter, use the card visual, introduce the number column, and you can view it:

vyinliwmsft_6-1665654339544.png

vyinliwmsft_8-1665654372249.png

 

 

Is this the result you would expect?

 

Hope this helps you.

 

Best Regards,

Community Support Team _Yinliw

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

NandanHegde
Super User
Super User

You can leverage the partition/row number concept of SQL :

stackoverflow.com/questions/59622685/dax-expression-for-row-number-partition-by-order-by-equivalent




----------------------------------------------------------------------------------------------
Nandan Hegde (MSFT Data MVP)
LinkedIn Profile : www.linkedin.com/in/nandan-hegde-4a195a66
GitHUB Profile : https://github.com/NandanHegde15
Twitter Profile : @nandan_hegde15
MSFT MVP Profile : https://mvp.microsoft.com/en-US/MVP/profile/8977819f-95fb-ed11-8f6d-000d3a560942
Topmate : https://topmate.io/nandan_hegde
Blog :https://datasharkx.wordpress.com

Helpful resources

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

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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