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

Dynamic Top N slicer based on a measure for building a Line Chart

I have a table "Tags" that looks like this:

IDTagsIDUserNameisTrueDate
11PythonTrue01/01/2020
210CFalse01/05/2020
1100PythonFalse01/06/2020
11000PythonTrue01/01/2021
2110CTrue01/01/2021
311JavaFalse01/03/2021

 

I want to rank the number of times each "Name" appears in the table in order to filter the Top N through a dynamic slicer in a cumulative line chart. Date is linked to a Calendar table and IDUser to a User dimension

 

So far I have those measures:

 

_m_get_tags_rank = 
RANKX (
    ALLSELECTED ( 'Tags'[Name] ),
    COUNTA( 'Tags'[IDTag] ),
    ,
    DESC,
    DENSE
)
_m_is_top_selected = 
VAR SelectedTop = SELECTEDVALUE('TOP N'[Value])
RETURN
IF (
    [_m_get_tags_rank] <= SelectedTop,
    1,
    BLANK()
)
_m_cumulative_number_of_tags = 
CALCULATE (
    COUNTA( 'Tags'[IDTag] ),
    FILTER (
        ALL ( 'DimDate' ),
        'DimDate'[CalendarDate] <= MAX ( 'DimDate'[CalendarDate] )
    )
)

 

 

And a table for the slicer

 

TOP N = GENERATESERIES(0, 50, 5)

 

 

I use _m_is_top_selected to filter the 1s. This works when I show the information in a tabular visualization, but not when I create the cumulative line chart with "Name" as the legend and the Calendar table as the axis. I guess it has to do with the fact that they are not columns, so it cannot understand which rows should appear as 1 and which as blank.

 

I have thought on creating a similar solution using calculated columns, but it wouldn't work since my dashboard contains other slicers and filters, based, for example, in the User dimension.

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your question, the _m_get_tags_rank formula you created cannot be sorted correctly. I did the following test: Change the formula as shown in the figure below, and then click _m_get_tags_rank to sort in descending order. Through the Top N filter, the value that satisfies 1 can be correctly filtered.

_m_get_tags_rank = 
CALCULATE (
    COUNTROWS ( Tags ),
    FILTER ( ALL ( Tags ), Tags[IDTags] = MAX ( Tags[IDTags] ) )
)
_m_is_top_selected = 
VAR SelectedTop = SELECTEDVALUE('TOP N'[Value])
RETURN
IF (
    [_m_get_tags_rank] <= SelectedTop,
    1,
    BLANK()
)

v-henryk-mstf_0-1618454000811.png

v-henryk-mstf_1-1618454042813.png


If the problem is still not resolved, please provide detailed error information and data model. Let me know the result immediately, looking forward to your reply.

Best Regards,
Henry

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

3 REPLIES 3
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your question, the _m_get_tags_rank formula you created cannot be sorted correctly. I did the following test: Change the formula as shown in the figure below, and then click _m_get_tags_rank to sort in descending order. Through the Top N filter, the value that satisfies 1 can be correctly filtered.

_m_get_tags_rank = 
CALCULATE (
    COUNTROWS ( Tags ),
    FILTER ( ALL ( Tags ), Tags[IDTags] = MAX ( Tags[IDTags] ) )
)
_m_is_top_selected = 
VAR SelectedTop = SELECTEDVALUE('TOP N'[Value])
RETURN
IF (
    [_m_get_tags_rank] <= SelectedTop,
    1,
    BLANK()
)

v-henryk-mstf_0-1618454000811.png

v-henryk-mstf_1-1618454042813.png


If the problem is still not resolved, please provide detailed error information and data model. Let me know the result immediately, looking forward to your reply.

Best Regards,
Henry

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

amitchandak
Super User
Super User
Anonymous
Not applicable

Hi @amitchandak ! thanks for your answer.

 

When I was developing my solution, that was one of the articles I used as a reference. What I have so far is able to do the same thing as the article in a tabular visualization. Unfortunatelly it doesn't work in a line chart.

 

I have spoken with the user and he apparently accepts to use the filters on the right to edit the "N" for the Top filter. Anyway, I would like to find a proper way to solve this.

 

Thank you!

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.