Forum Discussion
Top N with multiple drill down
- 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- 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] ) ) - 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]
)
- 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.
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
- 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] ) ) - 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]
)
- javedbh10 years agoHelper II
OwenAuger Great work, worked like a charm, Thanks.
Two more things if possible:
- Need the data points sorted in each category
- Remove the gaps between bars if a bin name is missing in category (see the figure for reference).
- OwenAuger10 years agoSuper User
That's good :)
1. Unfortunately, from what I can tell, Power BI can't sort by two different columns in a table at the same time.
And in a clustered column chart, it doesn't seem possible to sort by value within each axis item, though I could be mistaken. Someone may have requested this(?)2. With the measures as we have defined them, I can't see a way of eliminating space between the bars where bin names are empty.
As an alternative, we could instead define two measures: [Top Bin Sum] and [Second Bin Sum], and put them in the correct order. But then you would see the bin sums but not the correspondingbin names on the chart - probably not good enough? In a table however, you could display text measures [Top Bin Name] and [Second Bin Name].