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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
moeconsult
Helper V
Helper V

Dynamic Date Dimension setting max year to current year

I need help creating a Dimdate with start year of 2012 and I want Max year to always be the current year, i.e 2020 would the max for based on date column in my factable [Booking Date] .

 

Any help will be appreciated .

1 ACCEPTED SOLUTION

Hi @moeconsult ,

 

Or like this?

Dimdate = 
VAR x = YEAR( TODAY() )
RETURN
CALENDAR(
    DATE( 2012, 1, 1),
    DATE( x, 12, 31 )
)

xxx13.PNG

 

Best regards,
Lionel Chen

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

8 REPLIES 8
parry2k
Super User
Super User

@moeconsult try something like this:

 

Calendar = 
VAR __m = YEAR( MAX ( Table1[Date] ) ) 
RETURN 
CALENDAR ( "2012,1,1", DATE ( __m, 12, 31 ) ) 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

This is giving me up to year 5000. and the Max booking date in my facttable is 21/03/2020 .

 

I had like to create a proper Datedimension table with Year,month,monthname, quater,week of year, week of month,day,day of week,day of year, day name. I think I can just date function to create this additional columns?

@parry2k 

@moeconsult not sure why, did you tested the solution provided by others, that should end your calendar till the end of the last date in your fact table. That would be the first place to check.

 

Also if you drop date from facttable in a card visual and select latest in the aggregation, what date you get?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Looks like there is a problem with my date from the fact table. I have dimdate created using the code below:

I have Parameter for Start year 2012 and endyear 2020

let

    StartDate = #date(StartYear,1,1),

    EndDate = #date(EndYear,12,31),

    NumberOfDays = Duration.Days( EndDate - StartDate ),

    Dates = List.Dates(StartDate, NumberOfDays+1, #duration(1,0,0,0)),

    #"Converted to Table" = Table.FromList(Dates, Splitter.SplitByNothing(), null, null, ExtraValues.Error),

    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "FullDateAlternateKey"}}),

    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"FullDateAlternateKey", type date}}),

    #"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([FullDateAlternateKey]), type number),

    #"Inserted Month" = Table.AddColumn(#"Inserted Year", "Month", each Date.Month([FullDateAlternateKey]), type number),

    #"Inserted Month Name" = Table.AddColumn(#"Inserted Month", "Month Name", each Date.MonthName([FullDateAlternateKey]), type text),

    #"Inserted Quarter" = Table.AddColumn(#"Inserted Month Name", "Quarter", each Date.QuarterOfYear([FullDateAlternateKey]), type number),

    #"Inserted Week of Year" = Table.AddColumn(#"Inserted Quarter", "Week of Year", each Date.WeekOfYear([FullDateAlternateKey]), type number),

    #"Inserted Week of Month" = Table.AddColumn(#"Inserted Week of Year", "Week of Month", each Date.WeekOfMonth([FullDateAlternateKey]), type number),

    #"Inserted Day" = Table.AddColumn(#"Inserted Week of Month", "Day", each Date.Day([FullDateAlternateKey]), type number),

    #"Inserted Day of Week" = Table.AddColumn(#"Inserted Day", "Day of Week", each Date.DayOfWeek([FullDateAlternateKey]), type number),

    #"Inserted Day of Year" = Table.AddColumn(#"Inserted Day of Week", "Day of Year", each Date.DayOfYear([FullDateAlternateKey]), type number),

    #"Inserted Day Name" = Table.AddColumn(#"Inserted Day of Year", "Day Name", each Date.DayOfWeekName([FullDateAlternateKey]), type text),

    #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Day Name",{{"FullDateAlternateKey", type datetime}})

in

    #"Changed Type1"

 

Can I have make this Dynamic so that latest year in my Dimdate table will always be the current year?

 

@parry2k 

 

Thanks

Hi @moeconsult ,

 

Or like this?

Dimdate = 
VAR x = YEAR( TODAY() )
RETURN
CALENDAR(
    DATE( 2012, 1, 1),
    DATE( x, 12, 31 )
)

xxx13.PNG

 

Best regards,
Lionel Chen

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

Greg_Deckler
Super User
Super User

Perhaps:

Dimdate = CALENDAR(DATE(2012,1,1),MAX('factable'[Booking Date]))

?

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

This is giving me up to year 5000. and the Max booking date in my facttable is 21/03/2020 .

 

I had like to create a proper Datedimension table with Year,month,monthname, quater,week of year, week of month,day,day of week,day of year, day name. I think I can just date function to create this additional columns?

camargos88
Community Champion
Community Champion

Hi @moeconsult ,

 

Try creating a table like:

 

DimDate = CALENDAR(DATE(2020; 1;1); MAX(factable [Booking Date]))

 

Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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