Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Marcin86
Frequent Visitor

Top 10 and percentage of total (year filtering)

how to calculate the total for a given year (total in year)and the percentage of the total for a given year (%)?

I have a slicer: 2023/2022/2021. I would like the top 10 of the year to appear after selecting the year.

 

nrnamedatevaltotal in year%
2023_0029z09.01.202371900001719110042%
2023_0121x20.03.2022663716016328882,3341%
2023_0096c17.02.202164609381310529849%
2023_0127v23.03.202338401801719110022%
2023_0179b14.04.20223672162,3316328882,3322%
2023_0040n13.01.202125842001310529820%
2023_0177m05.05.202321007601719110012%
2023_0176a05.05.2022210076016328882,3313%
2023_0182s13.04.202121007601310529816%
2023_0171d13.04.202321007601719110012%
2023_0178f09.05.2022195940016328882,3312%
2023_0180g05.05.202119594001310529815%
2023_0174h13.04.202319594001719110011%
2023_0173j13.04.2022195940016328882,3312%
1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Marcin86 ,

 

Please try:

percentage_of_the_total = DIVIDE(SUM('Table'[val]),[total_in_year])

total_in_year = CALCULATE(SUM('Table'[val]),FILTER(ALL('Table'),YEAR([date])=YEAR(SELECTEDVALUE('Table'[date]))))

Then apply the Flag measure to the visual's filter:

Flag = 
var _a = FILTER(ALL('Table'),YEAR([date])=YEAR(SELECTEDVALUE('Table'[date])))
var _b = RANKX(_a,CALCULATE(SUM('Table'[val])))
return IF(SELECTEDVALUE('Table'[date]) in ALLSELECTED('Table'[date])&&_b<=10,1)

vjianbolimsft_0-1686794458703.png

Final output:

vjianbolimsft_1-1686794491596.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Based on that data that you have shared, show the expected result very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-jianboli-msft
Community Support
Community Support

Hi @Marcin86 ,

 

Please try:

percentage_of_the_total = DIVIDE(SUM('Table'[val]),[total_in_year])

total_in_year = CALCULATE(SUM('Table'[val]),FILTER(ALL('Table'),YEAR([date])=YEAR(SELECTEDVALUE('Table'[date]))))

Then apply the Flag measure to the visual's filter:

Flag = 
var _a = FILTER(ALL('Table'),YEAR([date])=YEAR(SELECTEDVALUE('Table'[date])))
var _b = RANKX(_a,CALCULATE(SUM('Table'[val])))
return IF(SELECTEDVALUE('Table'[date]) in ALLSELECTED('Table'[date])&&_b<=10,1)

vjianbolimsft_0-1686794458703.png

Final output:

vjianbolimsft_1-1686794491596.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.