Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Quenril
Helper I
Helper I

Create a TopN DAX measure across multiple columns

Hello,

 

I am trying to create a series of card dashboards for the top performers in our business for each activity type. For each activity type I have a fact table with counts - screenshot example below of my 'Client meetings' fact table. Within this table each row contains a date and details of the company met with, followed by 3 columns with the names of the Consultants who attended the meeting ('Lead Consultant'; 'Consultant 1'; 'Consultant 2'). I would like to create a TopN DAX measure which returns the name of the Consultant with the most meetings - this needs to count the data in all 3 'Consultant' columns, and also be responsive to the date slicers I have on my dashboard page.  In the event of a draw I should like to return 2 names. Please can anyone help?

Thank you

Quenril

Top N Client Meetings.png

 

16 REPLIES 16
Quenril
Helper I
Helper I

Hi Ashish,

 

Please try this file: Client Meetings table for Top Consultant Recurrence.xlsx

 

Thank you so much 😊 

Quenril

Quenril
Helper I
Helper I

Hi Ashish,

Adding a 'To date' is no problem I can do that for my data without issue. Regardless of the data range selected, I would like only the Consultants who are in the business the date that the dashboard is being viewed to be included (i.e. the live date the line Manager is looking at the report). For example, if Consultant A was top performer and Consultant B second for both March and April 2024, but Consultant A left the business on the 20th April, if I ran the report at the end of March the result would be Consultant A, but if I ran the report at the end of April it would be Consultant B (with Consultant A being excluded from the calculation). Is that possible? 

Thank you

Quenril 

Hi,

Share revised Excel file with a To Date column.  I can try.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Quenril
Helper I
Helper I

Hi Ashish,

 

Please try this link:  Client Meetings table for Top Consultant Recurrence.xlsx

 

In this example, if we assume Consultant A is no longer working for the company the result I am looking for would be Consultant D (2 Client meetings attended). In the 'Consultant lookup' table I'm happy to add a column with the departure date or a 'Current employee Y/N' column to aid the measure as needed.

 

Thank you

Quenril

There should be a "To Date" column in the Consultant table.  If you select a date range in the slicer, then for a consultant to be considered, should he/she be in the Organisation all through out the selected date range or would the consultant be considered even if he/she has been in the Organisation for a portion of the selected date range?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Quenril
Helper I
Helper I

Hello Ashish,

 

Amazing, that was so simple, I need to remember that filters applied in Query Editor load so thank you. 

 

Sorry to be a pain (😶) however I have one final query to finesse this formula.... Depending on the time period I select in my slicer, sometimes the Top N Consultant Name is someone who has actually now left the business. Is there an easy way I can filter the measure to include just current Consultants? I don't want to delete the underlying data in the 'Client Meetings' table as I need that for my aggregate YOY measures etc.

 

I have a seperate table called 'Consultant lookup' which contains all the names, departments, codes and the dates when each person was joined the business. For people who moved teams internally that is also indicated on this sheet. Is there any way I can use this to limit my Top N formula to just individuals who are still working for our company as of the current date? I can add a further column with a simple 'In the business on current date Y/N' type selection if that helps?

 

This is an example of my Consultant lookup table:

Effective from dateConsultant NameDivision
01/01/2020Consultant ABusiness Tranformation
01/04/2022Consultant BFinance
08/04/2022Consultant CBoard
15/04/2023Consultant DBoard
07/06/2023Consultant EBusiness Tranformation
31/10/2023Consultant ADigital & Technology
31/10/2023Consultant DSales & Marketing
01/11/2023Consultant FDigital & Technology

 

Thank you

Becky

Hi,

Share the dowload link of an Excel file.  Have the 2 input tables there and via Pivots/formulas show the expected result.  I will try to translate those formulas into the DAX language.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Quenril
Helper I
Helper I

Hello Ashish,

Thank you so much for this. So the formulas are both working however Measure 2 is returning a blank result. This is actually correct as in my data table where I have unpivoted the 3 Consultant columns (which included blank fields), the majority of my 'Consultant Name' column is showing as blank. Is there a way that after I have unpivoted the columns I can remove any rows in my fact table where that 'Consultant Name' column is blank? Essentially those rows now contain duplicate data.

Thank you so much

Quenril

You are welcome.  In the Query Editor, after the Unpivot step, filter out the blanks/nulls.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Quenril
Helper I
Helper I

Hi Ashish,

Sure thing. Please see table image with dummy data. The result I am looking for is that I would like to return the name which occurs with the highest frequency in the 'Consultant Name'  column. So in this example I would be looking for the result to be "Consultant A". In the event that there are multiple names with equal-highest recurrence, I would like the formula to return multiple names. In addition, I would like the measure to observe my date slicer from my 'Rolling calendar' table, so that the measure obeys the selected date range. Please can you help?    Top N Client Meetings.png

 Thank you

Quenril

 

I requested you to "Share data in a format that can be pasted in an MS Excel file."  I cannot do anything with just an image.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

My apologies, I can't see how to upload an excel/csv file. Can you copy-paste from this table?

 

Date of MeetingCompany NameContact NameLead of InviteeConsultant Name
31/10/2023Company AContact ALead ConsultantConsultant A
30/10/2023Company BContact BConsultant Attendee 1Consultant B
31/10/2023Company CContact CConsultant Attendee 2Consultant A
31/10/2023Company DContact DLead ConsultantConsultant C
31/10/2023Company EContact EConsultant Attendee 1Consultant B
31/10/2023Company FContact FLead ConsultantConsultant D
01/11/2023Company GContact GConsultant Attendee 1Consultant A
05/11/2023Company HContact HLead ConsultantConsultant D
16/11/2023Company IContact IConsultant Attendee 1Consultant E

 

Thank you

Quenril

Hi,

These measures work

Measure = COUNTROWS(Data)
Measure 2 = CONCATENATEX(TOPN(1,VALUES(Data[Consultant Name]),[Measure]),Data[Consultant Name],", ")

Hope this helps.

Ashish_Mathur_0-1714562167209.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

In the Query Editor, select all columns other than the Consultant columns, right click and select "Unpivot Other Columns".  You may delete the attribute column.  Write these measures

Instances = countrows(Data)
Measure = CONCATENATEX(TOPN(1,VALUES(Data[Value]),[Instances]),Data[Value],", ")

Hope this helps.

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

Thank you for this. I have done the unpivot which worked fine. I don't understand fully the way these measures are intended to work, however if I tell you the results they are giving me I'm hoping you understand...

 

The 'Instances' measure is giving me a total row count for all meetings within a given period (as I have unpivoted each Consultant is listed in a seperate row so 'Instances' is returning the total count of every Consultant going out on a visit).

 

The 'Measure' measure you provided me with is accepted and not returning an error, however it is returning a blank card. I tried swopping the 'Instances' measure you gave me for a measure I have calculating the total number of Consultants and that did return a name, although not the correct one (it returned the 2nd highest result, instead of the first). We are close! Any more ideas please? 

 

Please see screenshot attachedTop N formula.png

 

 Thank you

Quenril

Hi,

Share some dummy data to work with and show the expected result.  Share data in a format that can be pasted in an MS Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.