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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Giada90
Helper III
Helper III

dynamic date selecting a date filter

Hi, 

I need to create a text with dynamic date based on selected filter date.

For example if I select 2023 I need to see

 

-starts before  01/01/2024 and end after 01/01/2025.

-starts before 01/01/2024 and end on 31/12/2024.

-starts and end in 2024.

-starts in 2024 and ends after 01/01/2025.

 

if I select 2022 I need to see the same but with one year before etc.....

how can I do? which formula I need to use to have this date?

thanks

 

1 ACCEPTED SOLUTION
Deku
Super User
Super User

 

var Year = Selectedvalue( table[year] ) + 1
var startofYear = DATE( Year, 1, 1 )
var startofFollowingYear = DATE( Year + 1, 1, 1 )
var endofYear = startofFollowingYear - 1
return
"-starts before " & startofYear & " and end after " & startofFollowingYear & "." & CHAR(10) &
"-starts before " & startofYear & " and end on " & endofYear & "." & CHAR(10) &
"starts and end in " & Year & "." & CHAR(10) &
"starts in " & Year & "and ends after " & startofFollowingYear & "."

 

You might want to wrap the dates in FORMAT( , "dd/mm/yyyy") to format them as you like


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

9 REPLIES 9
Deku
Super User
Super User

 

var Year = Selectedvalue( table[year] ) + 1
var startofYear = DATE( Year, 1, 1 )
var startofFollowingYear = DATE( Year + 1, 1, 1 )
var endofYear = startofFollowingYear - 1
return
"-starts before " & startofYear & " and end after " & startofFollowingYear & "." & CHAR(10) &
"-starts before " & startofYear & " and end on " & endofYear & "." & CHAR(10) &
"starts and end in " & Year & "." & CHAR(10) &
"starts in " & Year & "and ends after " & startofFollowingYear & "."

 

You might want to wrap the dates in FORMAT( , "dd/mm/yyyy") to format them as you like


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

thanks!

@Deku thanks, but if I try the formula I get error from the second var, the first var works correctly

updated from 01 to 1 let me know if that was it


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

@Deku it doesn't take the first variable year inside the second variable startofyear

Assume you year is a string you will need to wrap the selectedvalue in int() to convert the text to a number


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Anonymous
Not applicable

Hi @Giada90 ,

 

Sorry, I don't really understand what you mean, can you provide more examples? Are you trying to get the following text based on the selected year, or are you filtering the data for the following date range?

vmengmlimsft_0-1741765531968.png

 

 

 

 

Best regards,

Rimmon Li

@Anonymous hi, I'm trying to get the following text based on the selected year, thanks

Deku
Super User
Super User

Is this the kind of thing you are looking to see?

https://evaluationcontext.github.io/posts/IslandsAndGaps/

 

1000016132.jpg


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.