calculated column showing top

Forum home » Delegate support and help forum » Microsoft Power BI training and help » Calculated column showing top 1, top 2 value etc. | Forum

Calculated column showing top 1, top 2 value etc. | Forum

resolvedResolved · Medium Priority · Version 2016

Andy has attended:
Introduction to Management course

Calculated column showing top 1, top 2 value etc.

Hello,

I'd like to display a visual showing the highest and second highest (and so on) ID per day based on sales. I don't want this to interfere with other filters on the same visual so I'd like to add calculated columns with this data.

Example of my table below; what I'd like is Top1 and Top2 columns showing the highest and second highest IDs per day based on sales.

Date Sales ID Top 1 Top 2
10/01/2020 10 A D A
10/01/2020 5 B D A
10/01/2020 1 C D A
10/01/2020 25 D D A
11/01/2020 20 A B A
11/01/2020 45 B B A
11/01/2020 6 C B A
11/01/2020 12 D B A
12/01/2020 1 A C B
12/01/2020 15 B C B
12/01/2020 20 C C B
12/01/2020 3 D C B


Thank you
A

RE: Calculated column showing top 1, top 2 value etc.

Hi Andy,

Thank you for the forum question.

I am not sure I understand what you want, but I hope this can help you to get what you want.

If you create a calculated column with the DAX below, you get each day ranked by sales. If you filter by the column, a visual can display the ID and the sales for Top 1 or Top 2 or Top..........


Rank all rows as Column per day =
RANKX(
FILTER(
'Table1',
'Table1'[date]=EARLIER(Table1[Date])
),
'Table1'[Sales]
)

If you want to display the Top 1 ID in a new column:

Top 1 ID = if(Table1[Rank all rows as Column per day]=1,Table1[ID])

If you want to display the Top 2 ID in a new column:

Top 1 ID = if(Table1[Rank all rows as Column per day]=1,Table1[ID])

But I cannot find a way of displaying the ID in each row.

If you want to ignore filtering in a visual, you will need to tell Power Bi which filters you want to ignore by using the All function. I do not know how you have filtered your visuals but if you have filtered the visual by "Rank all rows as Column per day" but still want to see the sale for the rest of the IDs you will need a measure:

Sales All=Calculate(sum(Sales),All([Rank all rows as Column per day])



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Sat 6 Feb 2021: Automatically marked as resolved.

 

Training courses

 

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Power BI tip:

Query Editor Shortcuts

Ctrl + E: Open or close the Query Editor.
Ctrl + F: Find within the Query Editor.
Ctrl + H: Replace within the Query Editor.
Ctrl + D: Duplicate selected query.
Ctrl + ; (semicolon): Insert a step to create a custom column.
Ctrl + M: Enter the formula bar for the selected step.

View all Power BI hints and tips


Server loaded in 0.06 secs.