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
Anonymous
Not applicable

Table with percentage as total (of the top 5 I selected)

Hi, I have a set of data and I would like the view to as follows:-

terrell95_0-1646199499350.png

 

I already managed to get Top 5 from my dataset using TopN. But now I would like to know the percentage of subtotal in the total row.

 

May I know how can I do that?

 

Thanks in advance!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a simple sample like below.

 

Picture1.png

 

Top five Revenue: =
VAR topfiverev =
CALCULATE (
SUM ( Data[Revenue] ),
KEEPFILTERS (
TOPN ( 5, ALL ( Data[Company] ), CALCULATE ( SUM ( Data[Revenue] ) ), DESC )
)
)
VAR allrev =
CALCULATE ( SUM ( Data[Revenue] ), REMOVEFILTERS () )
RETURN
IF (
HASONEVALUE ( Data[Company] ),
topfiverev,
FORMAT ( DIVIDE ( topfiverev, allrev ), "#.00%" )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

8 REPLIES 8
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a simple sample like below.

 

Picture1.png

 

Top five Revenue: =
VAR topfiverev =
CALCULATE (
SUM ( Data[Revenue] ),
KEEPFILTERS (
TOPN ( 5, ALL ( Data[Company] ), CALCULATE ( SUM ( Data[Revenue] ) ), DESC )
)
)
VAR allrev =
CALCULATE ( SUM ( Data[Revenue] ), REMOVEFILTERS () )
RETURN
IF (
HASONEVALUE ( Data[Company] ),
topfiverev,
FORMAT ( DIVIDE ( topfiverev, allrev ), "#.00%" )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Thanks for this! This is exactly what I am looking for!

If let say I have a column which is industry type of the company, in which part should I edit the formula in order to be able to filter it?

https://drive.google.com/drive/folders/1k8gKWmgrhHuP_6KU4HyVUKWEbsLfUXcF?usp=sharing

 

I have uploaded it here, please have a look and let me know if you cannot open it

Hi,

Thank you for your feedback.

Please check the link, because I cannot open the link.

Thank you.

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Hi,

Please try the below measure.

 

Top five Revenue for Bank only: =
VAR topfivebank =
CALCULATE (
SUM ( Data[Revenue] ),
KEEPFILTERS (
TOPN (
5,
CALCULATETABLE ( Data, FILTER ( ALL ( Data ), Data[Column1] = "Bank" ) ),
CALCULATE ( SUM ( Data[Revenue] ) ), DESC
)
)
)
VAR bankall =
CALCULATE (
SUM ( Data[Revenue] ),
FILTER ( ALL ( Data ), Data[Column1] = "Bank" )
)
RETURN
IF (
HASONEVALUE ( Data[Company] ),
topfivebank,
FORMAT ( DIVIDE ( topfivebank, bankall ), "#.00%" )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Hi Jihwan!

 

Thanks for the prompt reply!

 

I teste the code, it works! But heres a follow up question

 

Top five Revenue for Bank only: =
VAR topfivebank =
CALCULATE (
SUM ( Data[Revenue] ),
KEEPFILTERS (
TOPN (
5,
CALCULATETABLE ( Data, FILTER ( ALL ( Data ), Data[Column1] = "Bank" ) ),
CALCULATE ( SUM ( Data[Revenue] ) ), DESC
)
)
)
VAR bankall =
CALCULATE (
SUM ( Data[Revenue] ),
FILTER ( ALL ( Data ), Data[Column1] = "Bank" )
)
RETURN
IF (
HASONEVALUE ( Data[Company] ),
topfivebank,
FORMAT ( DIVIDE ( topfivebank, bankall ), "#.00%" )
)

 

Above are your code and 

CALCULATETABLE ( Data, FILTER ( ALL ( Data ), Data[Column1] = "Bank" ) ),
CALCULATE ( SUM ( Data[Revenue] ) )

Why this line of code only take my 1st line of item instead of adding it all together?

 

My dataset changes again, let me attach the table here 

Company Revenue Column1

a1000Bank
b800Bank
c750Bank
d700Bank
e500Bank
f450Bank
g350Bank
h185Bank
i15Bank
j155Bank
k32Bank
l447Bank
m1000Insurance
n800Insurance
o750Insurance
p700Insurance
q500Insurance
r450Insurance
s350Insurance
t185Insurance
u15Insurance
v155Insurance
w32Insurance
x447Insurance
a500Bank

New line of item in red.

 

In your code, it will only take Company A, which is 1000, but we know that the total of company A is 1500.

Hi,

Sorry I quite do not understand.

Could you please show me your sample pbix file with the additional line of a = 500 = bank? And the visualization that shows only a=1000, instead of a=1500?

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@Anonymous , assume you have measure TOP 5

 

Then create a measure like

TOP 5 new = if(isinscope(Table[Company]), [TOP 5], divide([TOP 5], calculate([TOP 5], allselected())))

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.