Forum Discussion

javedbh's avatar
javedbh
Helper II
10 years ago
Solved

Top N with multiple drill down

Here is my data:   MainCategory- SubCategory- Device- Lot- Bin_Name- Bin_Count Cat1 SubCat1 Dev1 Lot1 Bin 30 16 Cat1 SubCat1 Dev1 Lot1 Bin 31 22 Cat1 SubCat1 Dev1 Lot2...
  • OwenAuger's avatar
    10 years ago

    Hi there,

     

    Here is how I would do it, but there are definitely different ways of handling this :)

    PBIX example here:
    https://www.dropbox.com/s/t8ivi6u1iuq7856/Top%20N%20with%20multiple%20drilldown.pbix?dl=0

     

    1. I would create three measures that give you the bin count for top 2 bins at the three different levels. GENERATE/TOPN are used to give the top 2 per Maincategory/Subcategory/Device.
      Sum of Bin_Count = SUM( BinData[Bin_Count] ) 
      
      Sum of Bin_Count Top 2 Bin_Name per MainCategory = 
      CALCULATE ( 
      	[Sum of Bin_Count],
      	GENERATE (
          	    VALUES ( BinData[MainCategory] ),
          	    TOPN ( 2, ALL ( BinData[Bin_Name] ), [Sum of Bin_Count] )
      	),
      	VALUES( BinData[Bin_Name] )
      )
      
      Sum of Bin_Count Top 2 Bin_Name per SubCategory = 
      CALCULATE (
      	[Sum of Bin_Count],
      	GENERATE (
          	    VALUES ( BinData[SubCategory] ),
          	    TOPN ( 2, ALL ( BinData[Bin_Name] ), [Sum of Bin_Count] )
      	),
      	VALUES( BinData[Bin_Name] )
      )
      
      Sum of Bin_Count Top 2 Bin_Name per Device = 
      CALCULATE (
          [Sum of Bin_Count],
          GENERATE (
              VALUES ( BinData[Device] ),
              TOPN ( 2, ALL ( BinData[Bin_Name] ), [Sum of Bin_Count] )
          ),
          VALUES ( BinData[Bin_Name] )
      )
    2. Then create a measure that chooses between them depending which column is filtered. The logic here assumes you will only filter one of these columns at a time, but you could change this to handle cases where more than one is filtered.
      Sum of Bin_Count Top 2 Flexible =
      SWITCH (
          TRUE (),
          ISFILTERED ( BinData[MainCategory] ), [Sum of Bin_Count Top 2 Bin_Name per MainCategory],
          ISFILTERED ( BinData[SubCategory] ), [Sum of Bin_Count Top 2 Bin_Name per SubCategory],
          ISFILTERED ( BinData[Device] ), [Sum of Bin_Count Top 2 Bin_Name per Device],
          [Sum of Bin_Count]
      )