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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

DYNAMIC Date Slicers - Current YEAR and Current Quarter (Calculated Columns)

Hi all,

 

I'm having trouble using DAX to creae a dynamic date column in my date table. I am able to do this in Power Query, but would prefer to just do it in DAX so its a bit more simple for the client to take a look at.

 

I have my date table created like this:

 

dimCalendar =

VAR BaseTable = CALENDAR(MIN(JobsDB[End Date]), MAX(JobsDB[End Date]))
Return
ADDCOLUMNS(
BaseTable,
"Year",YEAR([Date]),
"Month",FORMAT([Date], "MMMM"),
"Month Number", MONTH([Date]),
"Calendar Month",FORMAT([Date],"MMMM YY"),
"Month Year", FORMAT([Date],"YYYY MM"),
"Report Date",FORMAT([Date],"YYYY/MM/DD"))
 
With that being said, how can I create the two calculated columns that will dynamically change to CURRENT YEAR ELSE Return the YEAR & Current Quarter ELSE return quarter? Would appreciate any help.

Thanks!
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Anonymous your explanation is super confusing isn't the year and quarter column already have that. ??

 

can you post example data? 



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.

View solution in original post

11 REPLIES 11
parry2k
Super User
Super User

@Anonymous 

dimCalendar =
VAR BaseTable = CALENDAR(MIN(JobsDB[End Date]), MAX(JobsDB[End Date]))
Return
ADDCOLUMNS(
BaseTable,
"Year",YEAR([Date]),
"Month",FORMAT([Date], "MMMM"),
"Month Number", MONTH([Date]),
"Calendar Month",FORMAT([Date],"MMMM YY"),
"Month Year", FORMAT([Date],"YYYY MM"),
"Report Date",FORMAT([Date],"YYYY/MM/DD"),
"Current Year", IF ( YEAR([Date])=YEAR(TODAY()), "Current Year", FORMAT([Date],"YYYY" ),
"Current Quarter", IF ( FORMAT([Date],"Q-yyyy")=FORMAT(TODAY(),"Q-yyyy"), "Current Quarter", "Q" & FORMAT( [Date], "Q" )
)

 

I updated Current Year/Current Quarter logic, you can tweak it as you see fit.

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



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.

Anonymous
Not applicable

Thank you so much this is wonderful

parry2k
Super User
Super User

@Anonymous your explanation is super confusing isn't the year and quarter column already have that. ??

 

can you post example data? 



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.

parry2k
Super User
Super User

@Anonymous if that is what you are looking for what @ryan_mayu provided, you need to change the quarter calculation. what @ryan_mayu provided will not work

 

dimCalendar =
VAR BaseTable = CALENDAR(MIN(JobsDB[End Date]), MAX(JobsDB[End Date]))
Return
ADDCOLUMNS(
BaseTable,
"Year",YEAR([Date]),
"Month",FORMAT([Date], "MMMM"),
"Month Number", MONTH([Date]),
"Calendar Month",FORMAT([Date],"MMMM YY"),
"Month Year", FORMAT([Date],"YYYY MM"),
"Report Date",FORMAT([Date],"YYYY/MM/DD"),
"Current Year", IF ( YEAR([Date])=YEAR(TODAY()), "Current Year", "Year" ),
"Current Quarter", IF ( FORMAT([Date],"Q-yyyy")=FORMAT(TODAY(),"Q-yyyy"), "Current Quarter", "Quarter" )
)

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



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.

Anonymous
Not applicable

Yes exactly. Right now, these dynamic date columns that was provided above would return

for Year ("Current YEAR" and "year")

For Quarter ("Current Quarter" and "Quarter"

What I want is a column that will provide this:

 

For the Quarter Column, we want (we are in Quarter 3 right now) "Q1", "Q2", "Current Quarter", "Q4")

For the Year Column, we want (in 2021 obviouly and we only have 2 years of data) "2020", and "Current Year)

@parry2k 

thanks for reminding this, I forgot to consider the year while calculating the quarter.





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

Proud to be a Super User!




ryan_mayu
Super User
Super User

@Anonymous 

Column = if('Table'[year]=year(today()),"current year","year")
Column2 = if('Table'[quarter]=quarter(today()),"current quarter","quarter")




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

Proud to be a Super User!




Anonymous
Not applicable

Let me rephrase -

 

I'm looking for Current Quarter ELSE return the whichever quarter is applicable to that row.. So I don't want it to just say "Current Quarter" And Quarter, I want it to return "Current Quarter" "Q2" "Q3" "Q4"

@Anonymous 

Column = if('Table'[year]=year(today()),"current year",'Table'[year])
Column2 = if('Table'[year]=year(today())&&'Table'[quarter]=quarter(today()),"current quarter",'Table'[quarter])




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

Proud to be a Super User!




parry2k
Super User
Super User

@Anonymous can you provide what these dynamic columns suppose to return, not fully clear from the post.



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.

Anonymous
Not applicable

I would like the quarter column to return "Current Quarter" if we're currently in the current quater, otherwise return all other quarters.

 

Same goes for year, I want to get the "Current Year" if we are in the current Year, otherwise, return the Year

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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