Forum Discussion
Sort conditional formatted column
- 4 years ago
Try replacing the DAX for 'RankRaw' with the following code:
RankRaw = VAR documentId = 'Data Table'[Document ID] VAR _Threshold = DIVIDE( CALCULATE( SUM('Data Table'[Difference]), ALL('Data Table'), 'Data Table'[Document ID] = documentId ), CALCULATE( SUM('Data Table'[Stock amount]), ALL('Data Table'), 'Data Table'[Document ID] = documentId ) ) VAR statusAdjustment = SWITCH( TRUE(), _Threshold < 0.5, 10000000, _Threshold < 0.9, 1000000, 0 ) RETURN documentId + statusAdjustmentYes, you will need to display the 'Rank' column if you want to sort based on it.
mattkocak Thanks for your reply! The "Difference column" is actually a measure and when i select it in the Fields menu, there is no "Column Tools".
Difference = Stock - Sold
Anonymous, ahh I see. In that case I feel like you have two options.
1. Use calculated columns instead of measures
2. Add the 'Icon flag' measure directly to the column and sort the table based on this. You could change its name in the visual to 'Status' or something similar that would make it appear a little more meaningful
Let me know if these solutions seem adequate or if I can help further.
- Anonymous4 years agoNot applicable
mattkocak To make the problem simpler, i have removed the calculated columns and left only the essential table and columns. But i am still facing the same issue - i am trying to sort all the icons in the "Difference" column, from red to orange to green, in that order whilst keeping the "Document ID" number in ascending order for similar icon flag colours. Is this possible?
There is no "Icon flag" in the list below - i think it's because it's a measure?
I have uploaded my PBIX file: https://drive.google.com/file/d/12ZQ3pH39k5f3YYceEb0rPviByJRGXRBO/view?usp=sharing
- mattkocak4 years ago
Kudo Kingpin
Thanks for the additional info, that clears the goal up a bit. So you will have to create two calculated columns for this. One is just used as an intermediary step (RankRaw), the other is to display/sort the actual rank in the table (Rank).
Below is the DAX for the calculated columns that I had created. Note that the display rules in the pbix that you provided (red, yellow, green) were the opposite of your orignal post. I corrected this in my calculations.RankRaw = VAR documentId = 'Data Table'[Document ID] VAR _Threshold = DIVIDE( CALCULATE( SUM('Data Table'[Difference]), ALL('Data Table'), 'Data Table'[Document ID] = documentId ), CALCULATE( SUM('Data Table'[Stock amount]), ALL('Data Table'), 'Data Table'[Document ID] = documentId ) ) VAR statusAdjustment = SWITCH( TRUE(), _Threshold < 0.5, 0, _Threshold < 0.9, 1000000, 10000000 ) RETURN (1000000 - documentId) + statusAdjustmentRank = RANKX( 'Data Table', 'Data Table'[RankRaw], , , Dense )Result:
Adjustments to the DAX can be done depending on the rules that you want to use to rank your rows. Let me know if this accomplishes what you are hoping or if I can help in another way.
- Anonymous4 years agoNot applicable
mattkocak Thanks for your help. I added the two calculated columns but it seems like both columns are not needed? I sorted by Rank column and removed RankRaw. But how to show Rank in ascending order so that the color order is from red to yellow to green? Is it possible to hide the Rank column from the table?