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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. 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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors