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.
Hello All -
I am looking to figure out how to sort a custom date column. The date column takes data from January 1st 2018 - current and assigns the relative quarter and year. What's different is that the custom date column deviates from quarters to months, if the month is within the current year. The DAX command below is what I am using to achieve this result:
DateAxisValue =
VAR CurrentYear = YEAR(TODAY())
Return
IF (
('Calendar Table'[YEAR]) = CurrentYear, 'Calendar Table'[MONTH], "Q" & ('Calendar Table'[QUARTER] & 'Calendar Table'[YEAR])
)
I'm at a loss in figuring out how to sort this column properly. I am trying to sort in calender order; meaning Q1 2018, Q2 2018, Q3 2018, ....... Q3 2019, Q4 2019, January, February, March, April, May, June.
I know the answer is probably simple, but I've looked at this problem for way too long. So now I am asking for help.
Thanks for any input!
@JMAlloway , in this case you need to compare date to current year.
Steps:
1) You need column in format Q1 2016 and column in format Year * 100 + Quarter (202001). You will sort first column by second column.
Dax example:
2) You need column in format Jan 2016 and column in format Year * 100 + Month (202001). You will sort first by second column.
3) After that create "Dynamic column" which will compare year versus current year. If year < current year then return "Quarter Year"
else return "Month Year".
Here is formula in Dax:
Hi, There are several solutions, but they all have one main thing - you need column which you will use for sorting.
Example: if you display date in this format "Q1 2019" you need column in format 201901; "Q2 2019" will have value 201902.
So when you choose option to sort column "Quarter Year" by this new column "Quarter Year Sort" it will be sorted the right way.
Example of adding sorting column:
Power Query: [Year]*100+Date.QuarterOfYear([Date] -- if you have column for year, but missing column for quarter, so you get it based on date column
Dax: YearMonthSort = YEAR('Date'[Date]) * 100 + QUARTER('Date'[Date]) -- if you have no column for year and quarter so get it from date column
Final step to set sorting:
Thanks for the reply, @nandic. I think this method would work under normal circumstances. My issue is that I have "Q2 2019" values and values that are "June 2020". So I have quarters and months that needs sorted in calendar year order. I'm having difficulting writing something similar to your example, although it has been the closest to working. I provided an image below that shows the result of your DAX example. It works for the quarters, but does not for months.
you can create a column that lists out [Month Number] and based on this column you can sort your [Month Name] column by using the sort by column feature in the modelling tab.
Thanks for your suggestion, Antriksh. Unfortunatly, the data goes back to January 1st 2018. If I try to do this, I recieve a cardinality error.
Here is how the visual shows up now:
In need this sorted in calendar order.
Thanks.
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 |
---|---|
42 | |
21 | |
21 | |
14 | |
13 |
User | Count |
---|---|
43 | |
39 | |
33 | |
18 | |
17 |