Ranking Values in a Virtual Table

I want to be able to reference the ranking in a virtual table in a data story/explanation (e.g. "Of the respondents in this group, the most common response is " {Answer Category with the highest rank}, making {percentage with the highest rank} of the responses.

I tried to create a temporary virtual table selecting only one question (see screenshot) but I’m getting a rank of 1 for all answer categories. I know this is a common problem and I’ve watched lots of videos, but I don’t seem to be able to solve it.

SummaryTable =

VAR Selection = “Q115”
//SELECTEDVALUE(Questions[Question Code])
VAR sumtable =SUMMARIZE (
FILTER (
‘Answers’,
Answers[Question Code] = Selection
),
Answers[Question Code],
Answers[Answer Category],
“CountCat”, [PeopleCount],
“Percent”,DIVIDE([PeopleCount],[Total by Question Count]),
“Ranking”,
RANKX (
ALLSELECTED ( Answers[Answer Category] ),
[PeopleCount],
,
DESC,
DENSE
)
)
RETURN
sumtable

ScreenShot1|690x499

Thanks for helping!

1 Like

@hastewar22 ,

This is a tough nut to crack. The problem with the approach you’re taking is that it’s not a virtual table - it’s a DAX calculated table, which only recalculates on manual refresh or when you first open the report. This will work the first time, but then when you change the value for the slicer, the table will remain static.

What you’re going to need to do here is build the ranking table as a true virtual table within a measure, and extract the proper value from that table for each cell of your table visual.

I’m working on this now. Confirmed in TE3 that the virtual table is calculating properly, but now need to get the proper value extracted, which is giving me some trouble. Hopefully, should have a solution for you later today.

  • Brian
3 Likes

I’m sorry I misled you with the examples. I really want to have a virtual table from which to draw the rankings but I tried to create an actual table just to work through it. That’s what you saw. I really appreciate your taking this on as I’ve been working a few days on it!

1 Like

@hastewar22 ,

OK, making progress. I’ve written and rewritten my DAX code six ways to Sunday and what should work isn’t working. Which almost always means there’s an issue in the data model, which I believe is the case here. Let me do some reworking on that, and I believe I’ll have a solution for you later tonight.

Super interesting problem…

  • Brian
1 Like

Thank you so much for helping out on this…and also confirming that it is not easy. I am very interested to see what you come up with.

1 Like

@hastewar22 ,

OK, I’ve got the virtual ranking table running like a champ:

Usually, the final step of pulling the proper value of [@RankPct] out of the table variable returning that in context as a scalar in the visual is very straightforward. However, I’m unexpectedly finding it incredibly difficult due to the structure of your data model. How open would you be to me restructuring your model to make it star schema compliant (basically merging Answers and NewLongTable, filtetered by Questions)?

I believe this will make the final step of this solution much easier, plus be more straightforward in general for other DAX measures.

Thanks.

  • Brian
2 Likes

Thank you so much, Brian!

1 Like

@hastewar22 ,

So, you’d be OK with a substantial revision to the data model?

  • Brian
1 Like

Well, I need to see the data model. Is it included somewhere that I’m missing? I’ve tried using the Dax query in my current data model and it produces a table…but I haven’t been able to draw info from that table. When I add a variable to choose the category with the top ranking, it does not like that because I’m not referring to a “base table”

1 Like

@hastewar22 ,

Sorry if my previous post was confusing. It wasn’t intended to be even a partial solution - just wanted to show you I was making progress and confirm that doing some revision to the data model would be OK (because in some cases, the original poster does not control the data model, so we have to work with it as given, but that doesn’t sound like the case here). WIll continue working this one and keep you posted.

  • Brian
1 Like

OK, I get it. Again, thank you for spending so much time on this. My EDNA membership has proven to be one of my best investments this year!

4 Likes

@hastewar22 ,

Haven’t forgotten about you - just had a couple of priority projects for Sam pop up. Have some dedicated time tomorrow blocked out for this to hopefully wrap it up. Thanks for your patience!

– Brian

Hi @hastewar22 and @BrianJ, I know you are in the middle of something here, but let us close this thread in the meantime.

Kindly, untick the solution button when you want to continue with the discussion again.

Thanks!