1 2 Previous Next 15 Replies Latest reply on Feb 5, 2017 3:12 AM by Andrew Watson

# top n

i want

sum top N sale/total(sum(sale))

• ###### 1. Re: top n

This question has been asked a lot....

Anyway, what you want to do isn't easy and depending how you want it laid out will affect the solutions available. Keeping in table format, as you have above:

1. Rank the price: RANK(SUM([Price])) Compute Using [Product]

2. Return the price for only the top 3: IF [rank] < 4 THEN SUM([Price]) END

3. Calculate the total for the Centre: { FIXED [Centre]:SUM([Price])}

4. Calculate the %: WINDOW_SUM(IF [rank] < 4 THEN SUM([Price]) END) / SUM({ FIXED [Centre]:SUM([Price])}) Compute Using [Product]

1 of 1 people found this helpful
• ###### 2. Re: top n

thank you.

your solution is great but when i drag calculation3 and drop into pivot, all cells in tableau show 1 for me.

• ###### 3. Re: top n

Check the formatting. 80% as an integer is displayed as 1. 0.8 rounds up to 1.

• ###### 4. Re: top n

just if i want show to user final value(Calculate the %).do you have any solution?

• ###### 5. Re: top n

It gets tricky. You need Product in the view to keep the Rank working correctly. Try this:

• Drag Product to the Detail shelf
• Create a new calculated field: IF FIRST()=0 THEN [Calculation3] END - Calculation3 is the calculated field returning the %

The results looks like this:

1 of 1 people found this helpful

• ###### 7. Re: top n

Sadly I can't load the workbook. I can share as many screenshots as you like but this has been built on the end of a confidential workbook just to quickly answer this question.

1 of 1 people found this helpful
• ###### 8. Re: top n

when i drag product into detail shelf tableau calculate % for all products not % of top 3 products

• ###### 9. Re: top n

Make sure you have the Compute Using set to Product for all of the table calculations in the view. Please share screenshots as well.

• ###### 10. Re: top n

hi Andrew.

do you remember last my quseion?

i want make a filter that user can select top 1 or 2 or 3 ... product. do you have any solution?

• ###### 11. Re: top n

If you want to make the top n dynamic you're almost there. Create a parameter with an integer data type.

In the accepted answer, step 4, in the formula provided it says '< 4'. Replace that with '<= '

Sent from Samsung Mobile

• ###### 12. Re: top n

Andrew excuse me for my questions.

i want know can we use fixed function for 2 dimention.like follow statement?

{ Fixed  [centers] and [Date ]:SUM([Sale])}

• ###### 13. Re: top n

Yes, but replace the and with , (a comma)

Sent from Samsung Mobile

1 of 1 people found this helpful
• ###### 14. Re: top n

hi Andrew.

i have you another question. if you answer it, I have been realy Indebted of you.

I live in iran. Calendar in my country is solar calendar. since Microsoft SQL not support from solar Calendar engineers for make database for date field use string data type instead date. and now i have a challenge with string date fields. i want now, how can change my date field to date without conversion to Georgian calendar?

1 2 Previous Next