Ravindra Bagale · Power BIसर्व coursesया course चे lessonsशोधाEnglish

Power BI · मराठी आवृत्ती

Power BI

13.17 RANKX आणि TOPN

RANKX(table, expression, value, order, ties) table मधल्या items ना expression नुसार rank देतो.

Product Rank =
IF(
    ISINSCOPE(Product[Product Name]),
    RANKX(ALL(Product[Product Name]), [Total Sales], , DESC, DENSE)
)

-- Rank dark stores by speed: fastest (lowest time) = rank 1
Store Speed Rank =
IF(
    ISINSCOPE(DarkStore[Store Name]),
    RANKX(ALL(DarkStore[Store Name]), [Avg Delivery Time (mins)], , ASC, DENSE)
)

Customer Rank in City =
RANKX(ALLSELECTED(Customer[Customer Name]), [Total Sales], , DESC)
Top 5 Products Sales =
CALCULATE(
    [Total Sales],
    TOPN(5, ALL(Product[Product Name]), [Total Sales], DESC)
)

Top 5 Share % = DIVIDE([Top 5 Products Sales], CALCULATE([Total Sales], ALL(Product)))

-- Calculated table of the 10 busiest dark stores
Top 10 Stores =
TOPN(
    10,
    ADDCOLUMNS(VALUES(DarkStore[Store Name]), "Orders", [Total Orders]),
    [Orders], DESC
)
  • ALL वापरून current item च्या बाहेरची comparison list मिळवा; selectionपुरता rank हवा तर ALLSELECTED विचारात घ्या.
  • Total row वर rank दिसू नये म्हणून ISINSCOPE वापरा. Product Name ने visual चं row grouping होतंय, अशाच rows वर ISINSCOPE TRUE देतो, त्यामुळे total row blank राहतो. HASONEVALUE एवढ्यासाठी पुरेसा नाही, कारण तो फक्त सगळे filters लागल्यावर एकच product उरलाय का एवढंच बघतो. Slicer मध्ये एकच product निवडला तर total row मध्येही एकच product असतो, आणि HASONEVALUE वापरला तर total row वरही rank दिसतो.
  • DESC मध्ये मोठी value rank1; ASC मध्ये छोटी value rank1.
  • SKIP ties:1,2,2,4; DENSE:1,2,2,3.

Store speed rank मध्ये blank timesना fastest समजू नका; eligible stores filter करा. Product / Customer Name unique नसेल तर unique key वर ranking ठरवा.

TOPN

Top N rows ची table देतो. शेवटच्या rank ला tie असेल तर Nपेक्षा जास्त rows येऊ शकतात. Deterministic selection हवी तर secondary sort key द्या. TOPN परत दिलेल्या rows sort करून देत नाही, म्हणून visual sort करा किंवा DAX query मध्ये ORDER BY वापरा. Calculated Top 10 Stores table refresh ला बदलते; slicerला dynamic top10 हवं तर visual filter किंवा measure वापरा.

फक्त chart मध्ये top10 दाखवण्यासाठी Filters pane मधला Top N पुरू शकतो. Share सारखा calculation हवा तेव्हा DAX उपयोगी.

या lesson साठी Ravi Sir's Cards

English cards