cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rzavgazaryan
Helper III
Helper III

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

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

 

can you post example data? 






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

@rzavgazaryan 

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.






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.





Thank you so much this is wonderful

parry2k
Super User
Super User

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

 

can you post example data? 






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

parry2k
Super User
Super User

@rzavgazaryan 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.

 






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.





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

@rzavgazaryan 

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!




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"

@rzavgazaryan 

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

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






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.





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
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power BI October Update 2021.jpg

Power BI Release

Click here to read more about the October 2021 Release!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!