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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Zephyrvic
New Member

How to get the percent of total for a TopN visual based on a selection on Date Slicer

Hello, 

I have a table visual which show the topN item-categories based on count of customer complaints.

However, I am also trying to get the percentage of total based on the date range that is selected on a  date-slicer in the report. E.g, if the user selects a date range of 1 July 2020 to 31st August 2020 The topN should also show me the percent of total for the two months and not percent of total of the topN.

Any idea how i can achieve this using DAX.

I am able to get the max and min date of the slicer selection using :

MAXX(ALLSELECTED('CALENDAR'), 'CALENDAR'[Date])
and 
MINX(ALLSELECTED('CALENDAR'), 'CALENDAR'[Date])
But i cannot use it to calculate the percent of total without applying the filter context in the topN to ensure i get the total for time period selected in the slicer.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

[% of Total Cases] =
DIVIDE(
    [Total Cases],
    CALCULATE(
        [Total Cases],
        ALL( T[sub_category] )
    )
)

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@Zephyrvic - You should be able to get the TOPN using TOPN or RANK and then divide that by ALL items. But hard to visualize without sample data.

Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

I already have my topN figured out. My table will show me the top20 for any date range i select in the slicer. However, the next thing i want to do is to calculate the percentage of total. But i want the total to be for the entire date range that is selected in the slicer and not the top 20.

For example, the below image shows me the top 20 categories by count of cases between July 1 and Aug 31 2020. now i want to add another column to show the percent of total cases within this same date range in the slicer selection. but when i attempt this, i keep getting the percent of topN  total (52,001) instead of the date range total (69,517) for each subcategory.

 

Screenshot_2.png

 

Anonymous
Not applicable

[% of Total Cases] =
DIVIDE(
    [Total Cases],
    CALCULATE(
        [Total Cases],
        ALL( T[sub_category] )
    )
)

Hello @Anonymous ,

 

Many thanks..

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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