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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
patshannon11
Frequent Visitor

Create Summary Ranked Table Containing a Measure that Connects to Original Source Table

My goal is to create a summary table containing a measure with a rank column that will update when filtering on different columns from the source data table.  I'm starting with a source data table similar to this:

 

ZIP CodeSettingServiceVolume
10001InpatientCancer15
10002InpatientCancer8
10003InpatientCancer2
10004InpatientCancer5
10001OutpatientCancer6
10002OutpatientCancer13
10003OutpatientCancer2
10004OutpatientCancer7
10001InpatientCancer5
10002InpatientCancer9
10003InpatientCardiac18
10004InpatientCardiac4
10001OutpatientCardiac5
10002OutpatientCardiac2
10003OutpatientCardiac1
10004OutpatientCardiac5
10001InpatientCardiac8
10002InpatientCardiac4
10003InpatientCardiac6
10004InpatientCardiac13
10001OutpatientNeurologic14
10002OutpatientNeurologic5
10003OutpatientNeurologic8
10004OutpatientNeurologic5
10001InpatientNeurologic6
10002InpatientNeurologic11
10003InpatientNeurologic3
10004InpatientNeurologic9
10001OutpatientNeurologic1
10002OutpatientNeurologic5
10003OutpatientOrthopedic6
10004OutpatientOrthopedic5
10001InpatientOrthopedic4
10002InpatientOrthopedic1
10003InpatientOrthopedic12
10004InpatientOrthopedic3
10001OutpatientOrthopedic2
10002OutpatientOrthopedic1
10003OutpatientOrthopedic5
10004OutpatientOrthopedic18

 

I then created a measure for Inpatient Mix % using the DAX below:

 

 

Inpatient Mix % = 
DIVIDE(CALCULATE(SUM('Data'[Volume]), 'Data'[Setting] IN { "Inpatient" }), SUM('Data'[Volume]))

 

 

I then created a calculated table with a rank measure using the DAX below:

 

 

Ranking Table = SUMMARIZE('Data','Data'[Service],"Inpatient Mix %",DIVIDE(CALCULATE(SUM('Data'[Volume]), 'Data'[Setting] IN { "Inpatient" }), SUM('Data'[Volume])))
Rank = RANK(DENSE, ALLSELECTED('Ranking Table'), ORDERBY('Ranking Table'[Inpatient Mix %], DESC), LAST)

 

 

 

 

 

This results in the following summary table:

 

RankService

Inpatient Mix %

1Cardiac80.3%
2Cancer61.1%
3Neurologic43.3%
4Orthopedic35.1%

 

I would utlimately like the Rank column to update when filtering on the column "ZIP Code" in the original source table, but I'm having trouble finding out how to create that relationship.  For example, If I filter on "ZIP Code = 10001" I would like the summary table to read as follows:

 

RankService

Inpatient Mix %

1Cancer76.9%
2Cardiac61.5%
3Neurologic28.6%
4Orthopedic

66.7%

 

Any help is appreciated!

 

@ryan_mayu 

@CoreyP 

1 ACCEPTED SOLUTION

Hello,

 

Someone very smart I know kindly provided the solution to this.

 

I see that @gmsamborn's solution also works, feel free to choose whichever most appeals to you. You may also accept multiple solutions.

 

First, we have to define these two measures

 

IN Ranking =
RANKX(
    ALLSELECTED(Data[Service]),
    [Inpatient Mix %]
)
 
OP Ranking =
RANKX(
    ALLSELECTED(Data[Service]),
    [Outpatient Mix %]
)
 
Then we define the composite value measure
Composite value = 0.25*[IN Ranking] + 0.75*[OP Ranking]
 
Finally, we define the composite rank
Composite Rank =
IF(
    ISINSCOPE(Data[Service]),
    RANKX(ALLSELECTED(Data[Service]), [Composite value])
)
 
The IF ISINSCOPE part just get rids of the rank at the total level.
 
As you can see below, both my "Composite Rank" and @gmsamborn's "My Rank" work just fine, also allowing for changing the ZIP slicer. If new Service values get added, the measure should dynamically respond with the correct values.
jjrand_0-1704293613948.png

 

View solution in original post

9 REPLIES 9
gmsamborn
Super User
Super User

Hi @patshannon11 

 

Would something like this help?

My Rank = 
VAR _Table = 
    SUMMARIZE (
        ALLSELECTED( 'Data' ),
        'Data'[Service],
        "Inpatient Mix %",
            DIVIDE (
                CALCULATE (
                    SUM ( 'Data'[Volume] ),
                    'Data'[Setting] IN { "Inpatient" }
                ),
                SUM ( 'Data'[Volume] )
            )
    )
VAR _Rank =
    RANK (
        DENSE,
        _Table,
        ORDERBY ( [Inpatient Mix %], DESC )
    )
RETURN
    _Rank

 

patshannon11.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!
jjrand
Helper I
Helper I

Hello,

 

Please see if this works

 

Rank = RANKX(ALL(Data[Service]), [Inpatient Mix %])
 
jjrand_0-1703792745484.png

 

Thanks for the response.  I'm ultimately wanting to rank several metrics (in addition to Inpatient Mix %) and do a composite score by service. 

 

Specifically, I believe I would need a way to return a Rank Value = 1 for Cancer (being able to rank in relation to the other services and with ZIP Code filtering - the rank value 1 would be filtering for ZIP Code 10001 in this example).  I then would be adding that rank to the other metric rankings for Cancer to get a composite ranking.

 

Sorry, hard to explain without being able to attach a file, hopefully this makes sense.

Which other metrics would you like to rank by? Can you provide some more sample data, with the columns you wish to be included in the calculation, and the expected result you would like to achieve?

For example, if I added the metric Outpatient Mix % to the dataset above:

Outpatient Mix % = DIVIDE(CALCULATE(SUM('Data'[Volume]), 'Data'[Setting] IN { "Outpatient" }), SUM('Data'[Volume]))

 

 

And added a corresponding rank measure:

OP Ranking = RANKX(ALL(Data[Service]), [Outpatient Mix %])

 

And filtered for ZIP Code 10001 resulting in the following table:

RankServiceOutpatient Mix %
1Neurologic71.4%
2Cardiac38.5%
3Orthopedic33.3%
4Cancer23.1%

 

I would like to be able to add the rank values  for Inpatient and Outpatient Mix for Cancer together for a composite rank (1 + 4 = 5)

 

 

I don't think I'm getting the full picture. How many metrics do you have? How are you calculating the composite ranking? If you are adding 1 and 4, then dividing by 2, you get 2.5. In fact, you get 2.5 for all of services, regardless of ZIP Code chosen. I can try to help, but I need more context.

The model I have applies a weight to Inpatient vs. Outpatient.  Assuming we apply a weight of 25% to Inpatient and 75% to Outpatient, here are the the Composite Calculation and Composite Rank I'd like returned when filtering on ZIP 10001.

 

For example, the Composite Calculation for Cancer would be (4*0.75 + 1*0.25 = 3.25).  Ranked vs. other services the Composite Rank would be 4.

 

ServiceInpatient Mix %IP RankOutpatient Mix %OP RankComposite CalculationComposite Rank
Cancer76.9%123.1%43.254
Cardiac61.5%338.5%22.252
Neurologic28.6%471.4%11.751
Orthopedic66.7%233.3%32.753

Hello,

 

Someone very smart I know kindly provided the solution to this.

 

I see that @gmsamborn's solution also works, feel free to choose whichever most appeals to you. You may also accept multiple solutions.

 

First, we have to define these two measures

 

IN Ranking =
RANKX(
    ALLSELECTED(Data[Service]),
    [Inpatient Mix %]
)
 
OP Ranking =
RANKX(
    ALLSELECTED(Data[Service]),
    [Outpatient Mix %]
)
 
Then we define the composite value measure
Composite value = 0.25*[IN Ranking] + 0.75*[OP Ranking]
 
Finally, we define the composite rank
Composite Rank =
IF(
    ISINSCOPE(Data[Service]),
    RANKX(ALLSELECTED(Data[Service]), [Composite value])
)
 
The IF ISINSCOPE part just get rids of the rank at the total level.
 
As you can see below, both my "Composite Rank" and @gmsamborn's "My Rank" work just fine, also allowing for changing the ZIP slicer. If new Service values get added, the measure should dynamically respond with the correct values.
jjrand_0-1704293613948.png

 

Thanks!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.