Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Top 5 in Rows and Columns

Hi Everyone,

 

Adding one more situation in the given scenario. (I am using SQL server direct query source hence unable to add new tables in model)

 

I want to filter category first and then in the filter category I want fetch top 5 associate name and top 5 divison in that particulat category.

 

Below is the Raw data

 

CategoryAssociateDivisionSpend
BusinessA1Road234
AssetA2Services343
ElectriicalA1Home223
LabourA4Services555
BusinessA5Group4234
AssetA6Medical234
ElectriicalA7Music344
LabourA6Home2344
BusinessA9Vehicle434
AssetA6Hospital434
ElectriicalA11Class2
LabourA12Veg23434
BusinessA13Cream234
AssetA6Home2344
ElectriicalA9Vehicle434
LabourA6Hospital434

Asset

A11Class2

 

Result would be say I filtered Category using page level Filter as Asset. Therfore under asser Top5 supplier and Top 5 spend would be like below snapshot. Mine motive is to segereate the Associate name by category and under cateory which are the Top5 associate and their spend with Top5 division(In column in powerBi)

 

 

 

 

 

 

Kindly help I am struggling on this from last couple of weeks. I am new in PowerBi therefore need support from you.

 

Regards

Uphar Tandon

  • Anonymous - Try replacing your ALL statements with ALLSELECTED. ALLSELECTED is kind of tricky but it might work for you. But, the issue is almost certainly your ALL statements.

4 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Greg_Deckler 

       

      Already gone throught  but still unable to create the DAX query or you can say the DAX is not given the correct output.

       

      I am using below DAX but when I am applying Page level Filter (Say in Category as Asset) the result it not accurate.

       

      Please find the DAX 

       

      SpendTop5= 
      VAR __topN = 5
      VAR __associate = 
          RANKX (
              ALL ( 'Table'[Associate] ),
              CALCULATE( 
                  [spend], 
                  ALLEXCEPT( 'Table', 'Table'[Associate] ) ),
              ,
              DESC,
              DENSE
          ) <= __topN
      VAR __division = 
          RANKX (
              ALL ( 'Table'[Division] ),
              CALCULATE( 
                  [spend], 
                  ALLEXCEPT( 'Table', 'Table'[Division] ) ),
              ,
              DESC,
              DENSE
          ) <= __topN
      RETURN 
          IF( __division && __associate, [spend] )

       

      If you could see, I am applying category filter in my dashboard therefore result is not accurate. I am looking for a DAX that can filter Category and then fetch top5 associate name and their Top5 Division.

       

      Thanks

      Uphar

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        Anonymous - Try replacing your ALL statements with ALLSELECTED. ALLSELECTED is kind of tricky but it might work for you. But, the issue is almost certainly your ALL statements.