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
Vincem35
Helper I
Helper I

TOPN Staff in Bar Chart

Dear Community, 

I am working with a transaction table and would like to highlight in a bart chart the top 3 staff.

I want to use TOPN function and not Rankx as the last one is very slow.

 

I created a measure like below

It its very fast - but when i pull it in a bar chart together with my column "Staff" i am getting all the Staff and not only the top 3.

 

 

Var Min_Date = "2019-01-01"
var Max_Date = "2019-12-31"
Var Table_Temp= 
    TOPN(3,
    CALCULATETABLE(
    SUMMARIZE('POS Boutique Transactions', 'POS Staff'[STAFF NAME],
    "Total Clients", DISTINCTCOUNT('POS Boutique Transactions'[Client])),
    all('POS Staff'[STAFF NAME]),
    'POS Boutique Transactions'[CLIENT TYPOLOGY] = "NEW",
    'POS Boutique Transactions'[VALID STAFF]= true(),
    'POS Boutique Transactions'[REGISTERED CLIENT] = true(),
    filter('POS Boutique Transactions','POS Boutique Transactions'[DT_VALID_TO] > Max_Date),
    filter('POS Boutique Transactions', 'POS Boutique Transactions'[DT_DOCUMENT]>= Min_Date && 'POS Boutique Transactions'[DT_DOCUMENT] <=Max_Date)), [Total Clients])

Var calc = SUMX(Table_Temp,  [Total Clients])

Return calc

 

 

Vincem35_0-1604542108297.png

How can i get only the top 3 staff in this chart?

Thanks for your help

3 REPLIES 3
v-lionel-msft
Community Support
Community Support

Hi @Vincem35 ,

 

v-lionel-msft_0-1604908681243.png

Have you tried using a filter instead of the TOPN() function?

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Vincem35
Helper I
Helper I

Thanks for your answer
still this way gives me a very slow performance... any chance to have a calulated table?

amitchandak
Super User
Super User

@Vincem35 , Try like


Total clients =
Var Min_Date = "2019-01-01"
var Max_Date = "2019-12-31"
return
calculate(DISTINCTCOUNT('POS Boutique Transactions'[Client]),
all('POS Staff'[STAFF NAME]),
'POS Boutique Transactions'[CLIENT TYPOLOGY] = "NEW",
'POS Boutique Transactions'[VALID STAFF]= true(),
'POS Boutique Transactions'[REGISTERED CLIENT] = true(),
filter('POS Boutique Transactions','POS Boutique Transactions'[DT_VALID_TO] > Max_Date),
filter('POS Boutique Transactions', 'POS Boutique Transactions'[DT_DOCUMENT]>= Min_Date && 'POS Boutique Transactions'[DT_DOCUMENT] <=Max_Date))

 

top 3 =
CALCULATE([Total clients],TOPN(3,all('POS Staff'[STAFF NAME]),[Total clients],DESC),VALUES('POS Staff'[STAFF NAME]))

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.