8 Replies Latest reply on Nov 23, 2017 4:28 PM by Maximiliano Luppi

# Calculating a Mode

Anyone know how to calculate a mode on a table in Tableau? I've attached some example data and the output I'm looking for is a table with the following:

CityMode
Calgary\$2
Edmonton\$5
• ###### 2. Re: Calculating a Mode

Hi Tracy

I believe that only shows me how to determine my mode graphically using a bar chart. I need to calculate my mode so that I can use it as part of another calculation. I've already tried the following:

WINDOW_MAX(IIF(COUNT([PRICE])==WINDOW_MAX([PRICE]),ATTR([PRICE]),0)

but it only works if I have the PRICE measure included in the rows like a histogram. I need to be able to calculate with Market on the rows shelf only.

• ###### 3. Re: Re: Calculating a Mode

Hi Ben

Take a look at the attached workbook based on the data you provided.

Sheet 1 calculate the mode for the whole series of values in measure Price. Sheet 2 calculate the mode per City

This solution was originally provided by Alan Smithee in his blog post Alan Smithee Presents: Statistics

I hope this helps

Best

Ramon

• ###### 4. Re: Re: Calculating a Mode

How would I then use the mode as part of a further calculation? I tried taking the price and multiplying it by 2. When I drag the result on to rows shelf, Tableau shows all the prices again, not just the mode.

• ###### 5. Re: Re: Re: Calculating a Mode

Hi Ben,

Take a look at the attached workbook with a solution to your question.

I created a calculated field "Price times 2" using the formula

```[Price] * 2
```

I created other calculated field just for label the table column header

Then,  I added the ATTR([Price times 2]) to mark Text and format it to display the value without decimal places

See Sheet 3 of the workbook to learn how to do it.

Best

Ramon

• ###### 6. Re: Re: Re: Re: Calculating a Mode

Still need some help on this. Now I'm trying to graph the mode for each day in a time series. Ideally for each date, I'd calculate the modes for two or more sets of data and chart them on the same graph. I've attached a worksheet. Is there any way I can use a table calculation to calc the mode for each day, for each data set? I tried using the above solution with measure values but it doesn't work (I guess because I can't make them dimensions)

 Date A B 1-Jan-14 8 10 1-Jan-14 2 2 1-Jan-14 8 4 1-Jan-14 6 7 1-Jan-14 4 9 1-Jan-14 0 0 1-Jan-14 5 10 1-Jan-14 10 0 1-Jan-14 4 7 1-Jan-14 1 2 1-Jan-14 1 5 1-Jan-14 7 5 1-Jan-14 8 2 1-Jan-14 3 8 2-Jan-14 2 10 2-Jan-14 6 5 2-Jan-14 4 5 2-Jan-14 5 0 2-Jan-14 1 4 2-Jan-14 6 5 2-Jan-14 8 10 2-Jan-14 4 10 2-Jan-14 2 4 2-Jan-14 10 9 2-Jan-14 3 3 2-Jan-14 0 7 2-Jan-14 7 10 2-Jan-14 3 3 3-Jan-14 7 3 3-Jan-14 9 9 3-Jan-14 8 4 3-Jan-14 2 6 3-Jan-14 10 1 3-Jan-14 2 10 3-Jan-14 3 1 3-Jan-14 4 1 3-Jan-14 10 9 3-Jan-14 8 2 3-Jan-14 5 5 3-Jan-14 2 3 3-Jan-14 6 0 3-Jan-14 7 0 3-Jan-14 6 6 3-Jan-14 8 1 3-Jan-14 6 6 4-Jan-14 5 4 4-Jan-14 7 4 4-Jan-14 6 6 4-Jan-14 0 4 4-Jan-14 10 10 4-Jan-14 9 8 4-Jan-14 1 8 4-Jan-14 9 2 4-Jan-14 8 3 4-Jan-14 3 8 4-Jan-14 0 7 4-Jan-14 1 2 4-Jan-14 0 4 4-Jan-14 4 8 4-Jan-14 0 0 4-Jan-14 6 1 4-Jan-14 10 1 4-Jan-14 0 5 4-Jan-14 6 8 4-Jan-14 10 10 4-Jan-14 6 4
• ###### 7. Re: Calculating a Mode

Any help?

• ###### 8. Re: Calculating a Mode

Hi

I'm not entirely sure, but I use this calculated field

{ FIXED STR([Price]):SUM([number of records])}

then use it with MAX aggregation

I could also use it in later calculations

I hope it is useful

Regards

Maximiliano