2
votes

I have a rather vexing situation in PowerBI. I developed a rank for my company's employees based on minimal time it takes them to do something. It's a ranking based on three separate factors; to do this, 'rank' had to be a measure.

So, I have a measure 'rank' which works as I intend it to:

Rank = IF ( HASONEVALUE( Query1[Employee Name] ), RANKX( ALLSELECTED ( Query1[Employee Name] ), [Rank_Total],, TRUE) )

where [Rank_Total] is the measure that creates a raw score of the three separate factors I mentioned earlier. So, [Rank_Total] creates a raw score, and [Rank] orders the raw values in [Rank_Total].

Here's where things get weird: if I want to simply choose the top 5 entries based on [Rank], I get nothing.

Here's what I mean: I created a measure called Test Measure, and I set it to:

Test Measure = IF( [Rank] < 6, 1, 0 )

This updated the matrix appropriately:

enter image description here

However, when I filter "Test Measure" to only include the "1's," this happens:

enter image description here

Does anyone have a suggestion as to why this is happening, and what an appropriate workaround is?

EDITED TO ADD: Here is a link to a Google public sheet for example data. The parameters I have are as follows:

Loan Count = COUNT(Query1[Loan Number])

Loan Count by Employee = Loan Count by Employee = CALCULATE([Loan Count], GROUPBY(Query1, Query1[Employee Name]))

Volume = Sum(Query1[Loan Amount])

Avg CTC Time = AVERAGE(Query1[CTC Time])

Avg CTC Time by Employee = CALCULATE([Avg CTC Time], GROUPBY(Query1, Query1[Employee Name]))

Now, for the Ranks. The Rank I have to based on three separate factors, in the following order:

  1. Lowest CTC Time
  2. Highest Loan Count
  3. Highest Volume

Here are the measures:

Rank_CTCLength = IF ( HASONEVALUE( Query1[Employee Name] ), RANKX( ALLSELECTED ( Query1[Employee Name] ), [Avg CTC Time by Employee],, TRUE) )

Rank_LoanCount = IF ( HASONEVALUE( Query1[Employee Name] ), RANKX( ALLSELECTED ( Query1[Employee Name] ), [Loan Count] ,, False) )

Rank_LoanVolume = IF ( HASONEVALUE( Query1[Employee Name] ), RANKX( ALLSELECTED ( Query1[Employee Name] ), [Volume],, False) )

I factored all three of them to make a "raw score" titled "Rank_Total":

Rank_Total = FORMAT([Rank_CTCLength]+[Rank_LoanCount]*POWER(10,-4)+[Rank_LoanVolume]*POWER(10,-8),"00000.00000000%")

From there, I created the final rank parameter titled Rank:

Rank = IF ( HASONEVALUE( Query1[Employee Name] ), RANKX( ALLSELECTED ( Query1[Employee Name] ), [Rank_Total],, TRUE) )

1

1 Answers

1
votes

With limited information, I think the reason why this happens is because when you apply a filter based on a measure (in this case Test Measure), it changes the data available in the visual and causes Power BI to reevaluate the other measures (e.g. Rank) based on the new data set.

Instead of creating a new measure for filtering purpose, my suggestion is to apply a Top N Filter on an existing column in the visual (e.g. EmployeeID), based on the measure (Rank).

Example and result: result


EDIT:

First of all, some suggestions. I noticed that you've created Avg CTC Time by Employee and Loan Count by Employee besides Avg CTC Time and Loan Count. This is actually not needed because the beauty of Measure in Power BI is that it will be evaluated based on current data context. Therefore, when you add Avg CTC Time measure next to Employee Name column in a matrix, it'll be evaluated as Avg CTC Time by employee automatically. (see screenshot below, same value for the two columns)

same result

I really appreciate the extra information you've provided in tackling this problem. Unfortunately, the data set is still not enough to reproduce the issue. It even works perfectly for the Test Measure you suggested failing in the question. Therefore I'm afraid you have to cross-compare with your original query and add more details to a point where the issue can be reproduced.