Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
VbOnline
Frequent Visitor

RANK of the Record in Calculated Table is Getting Reset when Applying Filter to pick 1 record.

I am facing a problem where, I want to rank all the records in a calculated tables based on certain parameters.

 

Once rank has been established, I want to only pick the record which I am interested in and I am interested in the Rank of that record among all the records.

 

Unfortunately, when I apply the filter, the rank is getting recalculated and with only 1 record, the Rank is changing to 1 than the original rank which was assigned along with all the records.

 

Any way to avoid this? Alternatively, is there a way to pick the record I need from the table without filter?

 

 

RankingTest =
VAR minselecteddate = "2022-04-01"
VAR maxselecteddate = "2022-06-30"
VAR MeasureCalc = CALCULATETABLE
(
SUMMARIZE(stn_list, stn_list[stn],stn_list[qtr])
,DATESBETWEEN(stn_list[depDate], minselecteddate, maxselecteddate)
,ALL (station_network[stationCode])
,all (BU[GroupName])
) // Has 260 Records

Below is my DAX Script:


var MeasureCalcAddMeasure = ADDCOLUMNS(MeasureCalc,"overallscore",[msroverallscore]) // Has 260 Records
var MeasureCaclAddRank = ADDCOLUMNS(MeasureCalcAddMeasure,"StnRank",RANKX(MeasureCalcAddMeasure,[overallscore],,DESC,Dense)) // Has 260 Records

var arpt = FILTER (MeasureCaclAddRank,[airport]="HYD") // with the filter, i am expecting 1 row with "Rank" Retained. But, the Rank is getting re-calculated and the Rank Is 1.
var selrank = SELECTCOLUMNS(arpt,"StationRank",[StnRank])
//var cntrows = COUNTROWS(arpt)

RETURN selrank

 

Finally, I need to original rank of the record I am interested in to be returned.

9 REPLIES 9
VbOnline
Frequent Visitor

I am still stuck with this problem. Any suggestions or ideas on how to get this working? I do not want to create calculated column as the filters will be a challenge. So, need a way to figure out the measure filter and avoid re-set of rank.

 

Thanks,

Vikram

VbOnline
Frequent Visitor

All, any help in this regard? 

v-yadongf-msft
Community Support
Community Support

Hi @VbOnline ,

 

Can you share with me some screenshots of your data after hiding sensitive information and tell me what is your expected output?

 

Thanks for your efforts & time in advance.

 

Best regards,

Yadong Fang

 

 

@v-yadongf-msft 

 

The below is my base data of sales:

 

stnQtrisMetroSalesAmount
HYDQ122Yes1000
SECQ122No950
MASQ122Yes400
LISQ122No750
LWDQ122Yes200

 

Based on sales and other factors, we calculate the Score and the Rank of that stn based on the score:

 

stnQtrCalculated Score via MeasureRank
HYDQ1222.255
SECQ1224.53
MASQ12251
LISQ1222.964
LWDQ1224.752

 

In the above, the Score and Rank are created using the DAX Script I posted in my original post.

 

This is the Rank for entire data set available to me.

 

In my Power BI Dashboard, I have a slicer for "Station".  What I am interested is, what is the Rank of the Station I am evaluationg. 

 

For example, for HYD Station, my rank is 5. I want to display this.

 

But, as the Slicer Selection is for HYD, the rank is getting re-evaluated to 1. This is happenning at this line and this is main culprit:

var arpt = FILTER (MeasureCaclAddRank,[stn]="HYD")

 

The Number of rows in the main calculated table is still 5:

var cntrows = COUNTROWS(MeasureCaclAddRank ) // This returns me 5 rows.

 

I just need the rank of station HYD from table MeasureCaclAddRank 

 

Hope this clarifies. Thanks

Hi @VbOnline ,

 

Please create a new column instead of a measure like this:

vyadongfmsft_0-1664330706830.png

The rank will not be re-evaluated.

vyadongfmsft_1-1664330751109.png

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

No, a calculated column does not work for me as the rank may vary based on slicer selection, so, the rank needs to be calculated on the fly which can only be possible via DAX.

 

Does Power BI does not provide a simple way to "filter a row from calculated table" with re-evaluating a measure?

VbOnline
Frequent Visitor

@Greg_Deckler I am not sure I understand your suggestion. By the time I am trying to rank my data, I have the measure (which is used to rank) available on the table.

 

And in the below table, I have my rank also correctly calculated:

var MeasureCaclAddRank = ADDCOLUMNS(MeasureCalcAddMeasure,"StnRank",RANKX(MeasureCalcAddMeasure,[overallscore],,DESC,Dense)) // Has 260 Records

 

At this point, I only need to "Pick" 1 row I am interested in. But, I am not sure there is any other option apart from FILTER.  A Simple "where condition" to pick the row from the table which has rank already available would do the job.

 

Can you please eloborate a bit on what you mean by "calculated column" on this table? Do you mean persist the data with measure into a table and add a calculated column to that persisted table?

 

Thanks

Greg_Deckler
Super User
Super User

@VbOnline Implement your Rank as a calculated column and not a measure?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  I am not sure I understand your suggestion. By the time I am trying to rank my data, I have the measure (which is used to rank) available on the table.

 

And in the below table, I have my rank also correctly calculated:

var MeasureCaclAddRank = ADDCOLUMNS(MeasureCalcAddMeasure,"StnRank",RANKX(MeasureCalcAddMeasure,[overallscore],,DESC,Dense)) // Has 260 Records

 

At this point, I only need to "Pick" 1 row I am interested in. But, I am not sure there is any other option apart from FILTER.  A Simple "where condition" to pick the row from the table which has rank already available would do the job.

 

Can you please eloborate a bit on what you mean by "calculated column" on this table? Do you mean persist the data with measure into a table and add a calculated column to that persisted table?

 

Thanks

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors