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
Hi Anonymous ,
For the highlighting, I'd suggest to create a measure that calculates the difference. Then, you can use that measure to do the color coding. Let's start with the initial situation from my previous example:
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.
The first measure (that you already have) is in my case this one:
ValueMeasure = SUM ( TableA[Value] )
Second, we need another measure that calculates the difference (%) between each month. I just created this one quickly, but pressumably you need to calculate it differently. The point of my reply is not showing how to calculate such a differences but more how you can use such a measure for color coding:
ValuesMeasureDiff% = VAR _valueCurrentMonth = CALCULATE ( [ValueMeasure], TableB[DateIndex] = MAX ( TableB[DateIndex] ) ) VAR _valuePreviousMonth = CALCULATE ( [ValueMeasure], ALLEXCEPT(TableA, TableA[Type] ), TableB[DateIndex] = MAX ( TableB[DateIndex] ) - 1 ) RETURN DIVIDE (_valueCurrentMonth - _valuePreviousMonth, _valuePreviousMonth ) + 0
Here the result using both of the measure underneath:
Now you can select the table visual and in the Visualisations tab on the right hand side, click on the downwards arrow on the Values field. Choose conditional formatting and then background color:
Fill in the settings accordingly. Make sure to use your Diff% measure:
And here the result:
There is even the possibility to create a color coding measure in DAX, which is pretty cool, too! It's less of a hassle if you wanna reuse the same settings on mutliple visuals.
Here you can find more information:
Conditional table formatting in Power BI Desktop - Power BI | Microsoft Docs
Let me know if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
- Anonymous4 years agoNot applicable
tom480 , I pray I haven't worn out my questions yet. I was finally able to get the dates to work. The problem was is that it wasn't recognizing the "DAX" created date, I had to go into PQ and create a date that way. My problem now is in understanding some of the formulas you put down. Also, at the bottom, just to be sure, I have a screen shot of the relationship I built. I got a little confused because you referenced (in one of the messages above, it gets confusing following the trail) something about a "period" I just created a reference between the two dates. Is that ok?
So I believe I only have this I'm confused on:
1) The first measure, ValueMeasure, (I haven not created Measures yet). Does it matter which table I "right-click" and create measure with?
2) I assume that in ValueMeasure = SUM ( TableA[Value] ), that "TableA" is my Invoice Data table, but not sure what [Value A] is?
3) Can you help walk me through the logic of in _valueCurrentMonth and Previous Month? and do I create them in the same manner as above in #1?
VAR _valueCurrentMonth = CALCULATE ( [ValueMeasure], TableB[DateIndex] = MAX ( TableB[DateIndex] ) ) VAR _valuePreviousMonth = CALCULATE ( [ValueMeasure], ALLEXCEPT(TableA, TableA[Type] ), TableB[DateIndex] = MAX ( TableB[DateIndex] ) - 1 )
My apologies if these are stupid questions.