Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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:
Solved! Go to Solution.
@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.
@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.
Thank you so much this is wonderful
@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.
@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.
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)
thanks for reminding this, I forgot to consider the year while calculating the quarter.
Proud to be a Super User!
@Anonymous
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"
@Anonymous
Proud to be a 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.
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
97 | |
85 | |
70 | |
61 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |