Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hello everyone,
I have a table with the following columns : KPI, Date and Value. Two of the KPIs are called Bonus Sales and another is Bonus Total and I did two measures accordingly. After I did a final one : Bonus Share = Bonus Sales/Bonus Total.
I want to highlight the Max and Min Values over a period of last 16 months in a line chart so I used the RANKX function :
Rank Desc Bonus Share =
RANKX(
FILTER
( ALLSELECTED(Data),
NOT(ISBLANK([Bonus Share])) ),
[Bonus Share],
, DESC, Dense )
The same for Asc and finally I used a "highlighter as :
Highlight Max_Min Bonus Share =
IF([Rank Asc Bonus Share] = 1 || [Rank Desc Bonus Share] = 1, "Red", "#FFFFFF00").
As all the values are showing in the line chart (and not only the Max and Min), I did a simple table and I saw that next to each month and to Bonus Share I have only 1 or 2. For the Rank Desc Bonus Share I have only 1.
I did the same in another line chart where I have a sinlge Measure called Total Sales and it worked perfectly.
What could be the issue ?
Thank you very much for your time.
Solved! Go to Solution.
@AntrikshSharma I played around and it is working.
Rank Desc Bonus Share =
RANKX(
FILTER
( ALLSELECTED(Data[Date].[Date]),
NOT(ISBLANK([Bonus Share])) ),
[Bonus Share],
, DESC, Dense )
That's the correct calculation. You were right about the aggregation on the Date level. The thing is that for my other graph it is working without that.
Thanks again for your time 🙂
@AntrikshSharma I played around and it is working.
Rank Desc Bonus Share =
RANKX(
FILTER
( ALLSELECTED(Data[Date].[Date]),
NOT(ISBLANK([Bonus Share])) ),
[Bonus Share],
, DESC, Dense )
That's the correct calculation. You were right about the aggregation on the Date level. The thing is that for my other graph it is working without that.
Thanks again for your time 🙂
@miketsilis Data[Date].[Date] - This is the wrong way of working with DAX you shouldn't use auto datetime tables, disable that in the options -> data load -> automatic date time and use a proper date table.
thanks for the advice and your time
@AntrikshSharma thanks for your reply.
I tried what you proposed but it is not working unfortunately.
By the way the Bonus Share is a Measure out of the division of two other Measures, so it is not a column.
I do not know why my calculation is working properly in another line chart which is using only one Measured called Total sales, but in that one where I show the ratio of Bonus Sales, it is not working properly.
@miketsilis The column that you must be using for visual must have a lower granuarity than the whole table? Data table might have more unique combinations or must have a primary key? RANKX has to build a temporary table where it evaluates measure in row context and filter context so the granualrity of the visual should match the granularity inside the RANKX so you need to use ALLSELECTED ( Data[Column] ) construct.
Here is an example:
Year Rank RANKX ASC =
RANKX (
ALLSELECTED ( Dates[Year] ),
[Total Sales], ,
ASC
)
Year Rank RANKX DESC =
RANKX (
ALLSELECTED ( Dates[Year] ),
[Total Sales], ,
DESC
)
Visual is using Year but if I change the ALLSELECTED ( Dates[Year] ) to ALLSELECTED ( Dates ) then the visual won't work as expected because Dates has a higher number of unique rows compared to Dates[Year].
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
11 |
User | Count |
---|---|
19 | |
14 | |
14 | |
11 | |
9 |