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
mmonca
New Member

Another rankx with slicer question

Hello,

So I have a dataset as

DateRegionFacilityUnitAmountRankYearQuarterMonthWeek EndingDoW
11 21 16West1221132201641111 26 16Mon
11 21 16West1221243201641111 26 16Mon
11 21 16East3773121201641111 26 16Mon
11 21 16East3773274201641111 26 16Mon
11 21 16East45541126201641111 26 16Mon
11 21 16East4554285201641111 26 16Mon
11 22 16West1221174201641111 26 16Tue
11 22 16West1221263201641111 26 16Tue
11 22 16East3773142201641111 26 16Tue
11 22 16East3773285201641111 26 16Tue
11 22 16East45541336201641111 26 16Tue
11 22 16East4554221201641111 26 16Tue
11 23 16West1221111201641111 26 16Wed
11 23 16West1221232201641111 26 16Wed
11 23 16East3773175201641111 26 16Wed
11 23 16East3773254201641111 26 16Wed
11 23 16East4554143201641111 26 16Wed
11 23 16East4554286201641111 26 16Wed


The goal is to rank each business unit each day. The full dataset has about 20 units across multiple regions and facilites with several years of daily data (so ~20 x ~250 x 4 = ~20,000 rows). The amount value is a calculated column comparing plan to actual. So by ranking we are looking for the unit that was closet to plan each day. I want to have a pivot table that is the following:

      West East   
      1221 3773 4554 
YearQuarterMonthWeek EndingDateDoW121212
201641111 26 1611 21 16Mon231465

 

This pivot table allows the user to expand/collapse any of the column or row headings. The ranking value will be shown as an average, giving, say weekly or monthly average daily rank for each unit. I will be adding slicers to the report allowing the users to filter date ranges and I can already imagine that some users will not want to see all units. I can't anticipate all the different combination of units users may see (i.e., all # 2 units from east, east+central, central, all # 3 units, etc, etc). I need the ranking to be updated so that when certain units or dates are sliced out the ranking doesn't take those units into consideration.

 

In an Excel spreadsheet this is straightforward. I would have slicers on a table and two calculated columns:

Aggregate = AGGREGATE(3,5,[@[Date]])

Rank = COUNTIFS([Date],[@[Date]],[Amount],"<"&[@Amount],[Aggregate],1)+1

The Aggregate column checks if the row is hidden/sliced/filtered and the rank has three conditions including the check if the row is visible. However, I would prefer to take advantage of PowerPivot's query and compression capabilities.

 

So this is what I have so far:

(calculated coumn) Overall rank= RANKX(Table1,[Amount],[Amount],1,Dense)

(measure) OverallRankVisible:=RANKX(ALLSELECTED(Table1),Table1[Amount],AVERAGE(Table1[Amount]),1,Dense)

(calculated column) Rank Each Day = RANKX(Table1,CALCULATE(SUM(Table1[Amount]),ALLEXCEPT(Table1,Table1[Date])),,1,Dense)

(calculated column) Daily Unit Rank1 =RANKX(FILTER(Table1,table1[Date]=earlier([Date])),Table1[Amount],[Amount],1,Dense)

(calculated column) Daily Unit Rank2 = CALCULATE(COUNTROWS(Table1)+1,FILTER(Table1,Table1[Date]=EARLIER(Table1[Date])&&Table1[Amount]<EARLIER(Table1[Amount])))

 

The overall rank does not consider the date. Rank each day column is an overall rank of the day instead of the units within the day. The measure is the only calculation affected by a slicer but it is an overal rank not considering each day. The two Daily Unit Rank columns produce the desired result but is not affected by slicing. I understand that the FILTER function is replacing the filter context created by the slicer. I'm not sure how to focus the count to produce the correct rank given the user selected filter context.

Thank you,

--mm

2 REPLIES 2
v-huizhn-msft
Employee
Employee

Hi @mmonca

For the pivot table you wanted, what do you mean of the last three part of results? For example, the highlighted in red line, the first row(Year Quarter Month Week Ending Date) show the column name, how do you get the 1,2 value?  What do you mean the 2,1 value(highlighted in yellow)? The 21221, 3772, 4554 are form  Facility column, it should be displayed in same column.


Capture1.PNG

>>I need the ranking to be updated so that when certain units or dates are sliced out the ranking doesn't take those units into consideration.

You want to select the Aggerate, Rank in Slicer, the rank will be update after the filter when you select value in slicer, right? The slicer will filter the rows in table. If you rank all the rows using measure, the rank will not be updated when click slicer.

Best Regards,
Angelia

Hi Angelia

Thanks for responding. So first off sorry for not being clear but that first row of 1 2  1  2  1  2 are the business units. The sample file had two units for each facility. Underneath that heading there is the sample for 11 26 16 with the rankings for the units being, in order, 2 3 1 4 6 5.

 

If I understand your question right, yes, I would like the ranking to be affected by the slicer. For instance if a unit is rank #1 on some day and then that unit is filtered out then the previous #2 should then become #1 and so on.

 

Also, I noticed that with a similar sumx measure I can generate a ranking by going to the pivot table options and show value as ranking smallest to largest. While this is a step in the right direction, what would be more helpful would be if the totals and rolled up amounts are not rankings. Absolute rankings should be at the daily level. At higher levels it would be best to have a average value. For instance, if 3 units have a cumulative total ranking score after a week 6, 10, & 14 then the week figure should be 1.2, 2, 2.8 and not 1,2,3. I think that having the average provides more details and is more useful (more challenging too,).

Thanks again everyone.

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.