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
Anonymous
Not applicable

Capture Rank position

Hi,

 

Report has Filter "Airport" (disconnected filter used for other reason).

Report has table with Airport and Capacity columns.

Created another calculated column _Rank (based on Capacity value).

Now I want to create another Calculated column "_NewColumn", to capture the Rank position of selected Airport.

PBI_Requirement.jpg

Above screen print, 'Airport1' is selected in Filter.

As per ranking, Airport1 has _Rank = 3.

Need to create new '_NewColumn', which populate with Airport1's _Rank (3), and so on.

Please help

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Here's the solution in full:

 

Airports.PNG

Measures:

Airport Rank = 
var __oneAirportVisible = HASONEVALUE( AirportCapacities[Airport] )
return
if ( __oneAirportVisible,
    RANKX (
        ALLSELECTED( AirportCapacities ),
        CALCULATE( SUM ( AirportCapacities[Capacity] ) )
    )
)
Selected Airport Rank = 
var __selectedAirport = SELECTEDVALUE ( AirportSlicer[Airport] )
var __oneAirportInView = HASONEVALUE( AirportCapacities[Airport] )
var __visibleAirports = ALLSELECTED( AirportCapacities[Airport] )
var __visibleAirportsWithRanks =
    CALCULATETABLE(
        ADDCOLUMNS(
            __visibleAirports,
            "_Rank", [Airport Rank]
        ),
        ALL( AirportCapacities )
    )
var __selectedAirportRank =
    MAXX(
        FILTER(
            __visibleAirportsWithRanks,
            AirportCapacities[Airport] = __selectedAirport
        ),
        [_Rank]
    )
return
    if ( __oneAirportInView, __selectedAirportRank )

Best

Darek

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Here's the solution in full:

 

Airports.PNG

Measures:

Airport Rank = 
var __oneAirportVisible = HASONEVALUE( AirportCapacities[Airport] )
return
if ( __oneAirportVisible,
    RANKX (
        ALLSELECTED( AirportCapacities ),
        CALCULATE( SUM ( AirportCapacities[Capacity] ) )
    )
)
Selected Airport Rank = 
var __selectedAirport = SELECTEDVALUE ( AirportSlicer[Airport] )
var __oneAirportInView = HASONEVALUE( AirportCapacities[Airport] )
var __visibleAirports = ALLSELECTED( AirportCapacities[Airport] )
var __visibleAirportsWithRanks =
    CALCULATETABLE(
        ADDCOLUMNS(
            __visibleAirports,
            "_Rank", [Airport Rank]
        ),
        ALL( AirportCapacities )
    )
var __selectedAirportRank =
    MAXX(
        FILTER(
            __visibleAirportsWithRanks,
            AirportCapacities[Airport] = __selectedAirport
        ),
        [_Rank]
    )
return
    if ( __oneAirportInView, __selectedAirportRank )

Best

Darek

 

Anonymous
Not applicable

Awesome!!!

 

It works for me.

Thanks a lot for greatr help.

 

Thanks,

Anonymous
Not applicable

Mate, you need a measure, not a calculated column. You drop the measure on your table and you've got what you wanted.

 

Try this measure.

[Selected Airport Rank] =
var __selectedAirport = SELECTEDVALUE ( Slicer[Airport] )
var __visibleAirports =
	SELECTCOLUMNS(
		CALCULATETABLE(
			AirportCapacities,
			ALLSELECTED (
				AirportCapacities[Airport]
			)
		),
		"Airport", AirportCapacities[Airport],
		"Capacity", AirportCapacities[Capacity]
	)
var __selectedAirportRank =
	CALCULATE(	
		RANKX (
			__visibleAirports,
			[Capacity]
		),
		AirportCapacities[Airport] = __selectedAirport
	)
return
	__selectedAirportRank

I have not yet tested it so it might not work. Tweaks will be needed in this case. But I'll test it and will tell you whether it works or not. If not, I'll craft the correct version (but you should try yourself as well).

 

Best

Darek

Mariusz
Community Champion
Community Champion

Hi @Anonymous 


Unfortunately Columns are calculated only on load of the model ( not dynamic ) , you could create a Measure that will display current selection in a Table or Matrix visual.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

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