Forum Discussion
Sorting and Comparing Columns Question
- 4 years ago
Hi Anonymous ,
Here a walkthrough on the first part of your question.
We have two tables, TableA is our FactTable and looks like this:
TableB is our Date dimension including a Date and the respective Index
The tables are connected via the Date column.
When using a matrix, without utilizing the DateIndex, we get the following result:
Obviously, PBI orders the strings alphabetically. As you suggested, we need an index column which PBI can use to sort it accordingly.
This is how you do it:
Go to the Data tab, select the column you'd like to sort (Date), click on Sort by column (Column tools ribbon) and choose the index column (DateIndex)
And the result should be like this:
Note, the Index Column needs to be in number format!
Let me know if his helps! 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/ - Anonymous4 years ago
SO, I was able to figure out the sorting combining the index value I created (tweaking it to 3*year + month) - but here is what I didn't know, that I got from your answer - that you could sort a column based upon another column. When I did that, I got it to work. NOW, I just need to understand the min/max and % difference solution you had. 😉
- 4 years ago
No worries, everyone is here to help. You can create a date table in Power Query or in DAX in the table itself. I will show you that later in this screenshot.
1) go to the table icon in the left navigation;
2) click on new table;
3) paste in your simple date table code. There's lot of examples to use, this is one from SQLBI.com. Remember in my code example, I am pointing to Table1[Period] which would represent the concatenated column you created - yours will likely be named something else;
4) Mark as date table;
5) Select the column that is the date column (will be Date);
6) Click OK. When successful you will see the 'Validated sucessfully' notification.
Always glad to help - Tom
Create a date table
Forgot to include step: Mark as date table...
WOW - tom480
First, thank you. Thank you very much. This is a lot to consume at once and, I hate to embarrass myself, I am very new to PBI and so some of this is difficult to grasp right now. The main way of pulling in data at this point has been just pulling in data from MS SQL tables so all that is going on in your TableDT creation is first time seeing and just trying to figure out where even to start with what I have - which is just two tables, one that lists my customers (companies) and then one that just pulls in the invoice amount and the month and year.
So my first thing I'll say (question) is - when you mention about making sure that a particular field is a date, the invoice table, believe it or not, does not have a date column...just a month and a year column. So when I created my "combined_date" column I just concantenated those into 2022/1, for example. Thus not sure that I could even convert that to a date field - but I'm probably skipping by a few steps here. Just trying to figure out where to start. Here's some screen shots on the data I have.
I think if I can grasp what you're teaching me here, it will go a long way to me furthering my understanding of PBI. I cannot thank you enough for your time.
- tom4804 years ago
Resolver I
No problem. Glad to help, I enjoy solving puzzles. You can also take your concatenated column and then simply mark it as a date type (in power query or DAX). I like this path because you still need to create a date table to get the time intelligence measures you want in your second question. And don't worry about being new to Power BI - it's a huge field and asking for help is part of the process - even if you have been using for a long time.My concatenated column marked as a date type
- Anonymous4 years agoNot applicable
I'm having a difficult time following the trail now, apologies. So, to tackle the highlighting issue. To break it down, I assume step 1 would be that I still need to format my date as a date type? (Even though it's a string of YYYY/MM (With no day?). Or do I need to create a date (remember, the SQL table just has month and year) by putting a '1" as the day - get it in the right format and then convert THAT do a date format?
Step 2 would be creating the date reference table via your code I re-pasted below? If so, Do I do that by Get Data->Blank Query and then putting in your code? (If so, could you help walk me through the code (is [Period] the date column?, what is FILTER and CALENDARAUTO() doing? And all the trailing code after that "CY" , FORMAT..etc) Sigh. Sorry....
TableDT =VAR MinYear = YEAR ( MIN ( Table1[Period] ) )VAR MaxYear = YEAR ( MAX ( Table1[Period] ) )RETURNADDCOLUMNS (FILTER (CALENDARAUTO( ),AND ( YEAR ( [Date] ) >= MinYear, YEAR ( [Date] ) <= MaxYear )),"Calendar Year", "CY " & YEAR ( [Date] ),"Month Name", FORMAT ( [Date], "mmmm" ),"Month Number", MONTH ( [Date] ))
Also - can you- tom4804 years ago
Resolver I
No worries, glad to help.
On question #1: I did a test and you can use your concatenated column as is, just mark it as a date type. From there you can change to the desired format (either in DAX or PQ). I added a screenshot of the formula below.
My concatenated column (of a year and month)
On question #2: SQLBI.com has a great article on creating a simple date table and probably does a better job explaining than me. In my opinion, you will need to do this to create the time intelligence measures you are looking for and for the most part, you can use the quick measures and skip learning a ton of advanced time intelligence DAX measures from scratch - quick measures are a great place to start. From there, conditional formatting can be applied and you can include the other measures you are looking for too.
Creating a simple date table in DAX - SQLBI
Always glad to help - [email protected]
- Anonymous4 years agoNot applicable
Also - could I not (on the sorting) create a DateIndex column inside the first table as just a column? It appears it's just the month #, which I already have. Also, how would this work with two years, 2021 and 2022?