简体   繁体   中英

Tableau - Count the maximum number

I have a dataset of employees by Segment, I was trying to find by each Segment what is the maximum sales % and how many employees achieved it.

First, I have created a calculated field, Target Achievement = Actual Sales / Target Sales, which works fine. Next, I would like to find what is the maximum Target Achievement and how many employees achieved in a filtered Segment?

I have tried using WINDOWS_MAX(), which returned the correct maximum Target Achievement, but I am not able to count the employees who have achieved the maximum.

Have you tried using the WINDOW_MAX in another calculation? Something like:

IF [TargetAchievement] = WINDOW_MAX([TargetAchievement]) THEN [EmployeeID] END

If that works you can count / countd that field.

An alternative, which may be more effective in this case, would be to use LOD calculations. Something along the lines of this: https://tarsolutions.co.uk/blog/create-fixed-bins-from-a-measure-in-tableau/

For your example the FIXED may need applying within the [TargetAchievement] field; "fixing" the Actual and Target Sales.

Create a binary calculated field 'achieved_max' as follows:

IF [Target Achievement] >= WINDOW_MAX([Target Achievement])
THEN 1
ELSE 0
END

After that try:

  1. Drag this new 'achieved_max' to Columns tab and drag Number of Records from Measures to Rows Tab.
  2. Filter by Segment

Number of Records with 'achieved_max' as 1 should be the the number employees who achieved the max target in the chosen segment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM