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
mark_endicott
Helper II
Helper II

DAX to replicate TopN filter to make it Dynamic, show Top all time - but by week

Hi, 

 

I am trying to replicate the function of a TopN visual level filter, so I can use it with a What If parameter to make it dynamic for the users of a report. 

 

I'd like to show the TopN of an item all time, but then break this down by the value that item acheived each week. I have tried several options, but I cannot seem to get it to ignore the date filter to find "all time" then re-apply the date filter to show the top N across time. 

 

Below is an example, where 'MARKET SALES' is my fact table, 'TABLE 1'[TABLE Code] is the item I want to do the TopN for and I'm trying to filter the Calculate table by the whole calendar.

 

SUMX (
    TOPN (
        [Top Number Selector Value],
        CALCULATETABLE (
            SUMMARIZE ( 'MARKET SALES', 'TABLE 1'[TABLE Code] ),
            ALL ( 'RLS CALENDAR' )
        ),
        [Total value], DESC
    ),
    [Total value]
)

 

Unfortunately this presents more items from 'TABLE 1'[TABLE Code] than the number selected in the TOP Number slicer.

1 ACCEPTED SOLUTION
mark_endicott
Helper II
Helper II

I have resoloved this by using a RANKX, inside a calculate that removes the calendar context from RANKX, here's my solution:

 

VAR Number_to_Rank = [Top Number Selector Value]
VAR Val = [Total value]
RETURN
    IF (
        CALCULATE (
            RANKX ( ALLSELECTED ( 'TABLE 1'[TABLE Code] ), [Total value] ) <= Number_to_Rank,
            ALL ( 'RLS CALENDAR' )
        ),
        Val
    )

View solution in original post

1 REPLY 1
mark_endicott
Helper II
Helper II

I have resoloved this by using a RANKX, inside a calculate that removes the calendar context from RANKX, here's my solution:

 

VAR Number_to_Rank = [Top Number Selector Value]
VAR Val = [Total value]
RETURN
    IF (
        CALCULATE (
            RANKX ( ALLSELECTED ( 'TABLE 1'[TABLE Code] ), [Total value] ) <= Number_to_Rank,
            ALL ( 'RLS CALENDAR' )
        ),
        Val
    )

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.