cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Helper I

## Rankings using DAX

Hello ,

My Data and implementation:

Schoolid           No. of Student           StudentGroup
---------------------------------------------------------
S1                            10                                  0-10
S2                             11                                11-20
S3                             20                                11-20
S4                             21                                21-30
S4                             35                                31-40

(Higher the count, top on rankings)

Now 'StudentGroup' stands for , group of student classified on number of students as below

-Row level security is implemented on the Schoolid , Let's say School with user Schoolid = S1 will able to see data only for school with id=S1

What i require?

What i want to find is rank of schools on the basis of No. of Student within the 'StudentGroup' in which particular School is falling in (refer above table).
"I wnat a rank of S2 as per No.of students within StudentGroup 11-20"

-I have created below DAX formula to get this value

RankMeasure:=MAXX(FILTER(ADDCOLUMNS(FILTER(Student,Student[StudentGroup] = "11-20"),"Rank",RANK.EQ(Student[No. of Student],Student[No. of Student])),Student[Schoolid] = "S2"),[Rank])

In the above formula what i am doing is :
1.Filtering Student on the basis of StudentGroup of selected Schoolid
2.Calculating ranking on the table return by first "FILTER"
3.Getting selected shool from the table return by second "FILTER"

But from msdn what i found is that , "ADDCOLUMNS" wont work with RANK.EQ.

I want to calculate ranking on the table which i am getting on the fly using FILTER.

Is there any other alternative to resolve above requirement. Please guide for the same.

Thanks

2 ACCEPTED SOLUTIONS
Resolver I

You take below approch to acheive your requirements.

You can prepare one more dimension table for School lets's say Student_RLS, Which will be the copy of table mentioned above

-There should be no relationship between copied table and original table , Import both the tables to power BI.

-Implement RLS , on copied table.

-Original table is independent of RLS implementation and All ranking calculations will be calculated on original table.

And your formula would be updated to below

RankMeasure:=MAXX(FILTER(ADDCOLUMNS(FILTER(Student,Student[StudentGroup] = "11-20"),"Rank",RANK.EQ(Student[No. of Student],Student[No. of Student])),Student[Schoolid] = VALUES(Student_RLS[Schoolid])),[Rank])

I am assuming , you are going to login with one school at a time to see report and your ranking measure as you have also mentioned that "Row level security is implemented on the Schoolid , Let's say School with user Schoolid = S1 will able to see data only for school with id=S1".

So your RLS will be implemented on Student_RLS[SchoolId].

Hope, this helps!

Thanks.

Helper I

Great!

Thanks @vinaypugalia

3 REPLIES 3
Resolver I

You take below approch to acheive your requirements.

You can prepare one more dimension table for School lets's say Student_RLS, Which will be the copy of table mentioned above

-There should be no relationship between copied table and original table , Import both the tables to power BI.

-Implement RLS , on copied table.

-Original table is independent of RLS implementation and All ranking calculations will be calculated on original table.

And your formula would be updated to below

RankMeasure:=MAXX(FILTER(ADDCOLUMNS(FILTER(Student,Student[StudentGroup] = "11-20"),"Rank",RANK.EQ(Student[No. of Student],Student[No. of Student])),Student[Schoolid] = VALUES(Student_RLS[Schoolid])),[Rank])

I am assuming , you are going to login with one school at a time to see report and your ranking measure as you have also mentioned that "Row level security is implemented on the Schoolid , Let's say School with user Schoolid = S1 will able to see data only for school with id=S1".

So your RLS will be implemented on Student_RLS[SchoolId].

Hope, this helps!

Thanks.

Helper I

Great!

Thanks @vinaypugalia

Microsoft Employee

Hi @daxesh,

Based on my test, this measure returns correct rank value as expect.
RankMeasure:=MAXX(FILTER(ADDCOLUMNS(FILTER(Student,Student[StudentGroup] = "11-20"),"Rank",RANK.EQ(Student[No. of Student],Student[No. of Student])),Student[Schoolid] = "S2"),[Rank])

From msdn, it says "columnName cannot refer to any column created using these functions: ADDCOLUMNS, ROW or SUMMARIZE.I", this means the columNname you used in RANK.EQ cannot be the new column which is created by ADDCOLUMNS. That is to say, the columnName must be the column existing in source table. In your scenario, the [No. of Student] can be used in Rank.EQ while the added column [Rank] cannot be used.

Thanks,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

#### Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Top Solution Authors
Top Kudoed Authors