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
Allen_R
Frequent Visitor

Complex Dynamic Ranking

I have an enormous data table called enterprise_combined which has vast amounts of data columns for mutiple years, weeks, kinds of business, and geographies.  I mocked up a basic example of the data table below.  I created two separate tables in my model to function as toggles for a measure I created called selected_results.  I've included a snippet of the measure and an exact version of the two toggle tables below as well.

 

Basically, I have a page that is filtered on 10 of the 13 kinds of business and the year 2025.  The page also has slicers for the user to select the View (Act Counts, Diff to Plan, Diff to PY, and Seas Ratios), Metric (Sales, Returns, and Net Sales), Kind of Business, and Week.  On the page I have a table that simply shows Market Area, Rank, VP, and the Selected Results measure.  The selected_results measure works perfectly given all the different combinations the user can choose from.  The table is sorted by the selected_results column from largest to smallest.  I eventualy want the table sorted by the Rank column once I get it working correctly.  Does anyone have suggestions on how I can modify my ranking measure (which is called top_or_bottom_vp) so that it properly ranks what's being displayed in the table?

A rudimentary mockup of the enterprise_combined data table:

yearweekkind_of_businessmarket_areavparea_namesales_actreturns_actnet_sales_actsales_planreturns_plannet_sales_plansales_pyreturns_pynet_sales_pysales_vs_planreturns_vs_plannet_sales_vs_plansales_vs_pyreturns_vs_pynet_sales_vs_py
20251RetailNortheastTom SelleckBurlington45050400425254004603542525250-1015-25
20252RetailNortheastTom SelleckBurlington405853204201540538520365-1570-852065-45
20251RetailNortheastTom SelleckAlbany6007552558535550610455651540-25-1030-40
20252RetailNortheastTom SelleckAlbany7207065069550645701606412520519109
20251RetailSoutheastBill ElliotAtlanta685806056007552567535640855801045-35
20252RetailSoutheastBill ElliotAtlanta6808060065570585670606102510151020-10
20251RetailSoutheastJohn WayneMiami77570705705806257707569570-10805-510
20252RetailSoutheastJohn WayneMiami695756207108562570580625-15-10-5-10-5-5
20251WholesaleNortheastTom SelleckBurlington255501500240502810517752633032105128530820-2555-275-2280-6555215-6770
20252WholesaleNortheastTom SelleckBurlington300002100279003255019053064529770220027570-2550195-2745230-100330

 

toggle_top25_view table:

view
Act Counts
Diff to Plan
Diff to PY
Seas Ratios

 

toggle_top25_metric table:

metric
Sales
Returns
Net Sales

 

Snippet of selected_results measure:

 

selected_results =
VAR SelectedView = SELECTEDVALUE(toggle_top25_view[view])
VAR SelectedMetric = SELECTEDVALUE(toggle_top25_metric[metric])
VAR SelectedKOB = SELECTEDVALUE(enterprise_combined[kind_of_business])

VAR SelectedResults =
	SWITCH(TRUE(),
		SelectedKOB = “Retail” && SelectedMetric = “Sales” && SelectedView = “Act Counts”, SUM(enterprise_combined[sales_act]),
		SelectedKOB = “Retail” && SelectedMetric = “Sales” && SelectedView = “Diff to Plan”, SUM(enterprise_combined[sales_vs_plan]),
		SelectedKOB = “Retail” && SelectedMetric = “Sales” && SelectedView = “Diff to PY”, [sales_%_to_PY],
		“Error”
	)
RETURN
SelectedResults

 

 

Current rank measure:

 

top_or_bottom_vp = 
VAR vpTable = 
    SUMMARIZE(ALLSELECTED(enterprise_combined), enterprise_combined[vp], "_results", [selected_results])
VAR currentResults = 
    CALCULATE([selected_results], VALUES(enterprise_combined[vp])) // Get the current VP context
RETURN
    IF([selected_metric] <> "Returns",
        RANKX(vpTable, [selected_results], currentResults, DESC, DENSE),
        RANKX(vpTable, [selected_results], currentResults, ASC, DENSE)
    )

 

 

Below is a snippet of actual results that I'm getting with fake names.  Everything is correct except for the Rank.

Market AreaRankVPSelected Results
Southeastern2Bob88.705
South Central 2Franky67,636
Southeastern3Willy67,633
North Central2John66,009
Western2Tommy64,214
South Central 3Hank63,913
Southeastern4Wilma61,276
Southeastern4Susan59,052

 

Any ideas on what I'm doing wrong here?

 

1 ACCEPTED SOLUTION

Yesterday when I posted this question, I couldn't tell if it actually got posted or not because the post woudn't show up anywhere.  At any rate, I ended up figuring out that if I remove market_area from my table visual, the ranking would work appropriately.  The ranking measure was basically ranking the VPs against one another based on the Selected Results BUT by Market Area as opposed to a whole.....if that makes sense.  So I ended up replacing market_area (which is a column name) with a measure that returned the market_area, and the ranking measure worked as it should.  I'm not sure why this worked, but it did.

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

I would consider normalizing the data somewhat, and I would probably also unpivot the metrics to make the selection and calculation easier.  But it will be some effort - not sure if you are willing to invest that.

Yesterday when I posted this question, I couldn't tell if it actually got posted or not because the post woudn't show up anywhere.  At any rate, I ended up figuring out that if I remove market_area from my table visual, the ranking would work appropriately.  The ranking measure was basically ranking the VPs against one another based on the Selected Results BUT by Market Area as opposed to a whole.....if that makes sense.  So I ended up replacing market_area (which is a column name) with a measure that returned the market_area, and the ranking measure worked as it should.  I'm not sure why this worked, but it did.

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.