Top N with Dynamic input


The objective is to implement a functionality that enables the dynamic modification of the number of bars displayed in the visual, based on the slicer selection, while concurrently altering the axis.

 

A video demonstration is available on YouTube

 

Refer below the sample data model

 

nandukrishnavs_0-1691493379272.png

 

Above data model can be created using GitHub Repository 

 

First we need to create a Numeric Range Paramter called Range.

nandukrishnavs_2-1691493952568.png

 

Next we need to create a Field Parameter called Dynamic Dimension

nandukrishnavs_3-1691494135969.png

 

Then we need to create a calculated column inside Dynamic Dimension table

 

 

 

 

 

Metric = [Dynamic Dimension]

 

 

 

 

 

nandukrishnavs_4-1691494331996.png

Create a sample base measure called Consumed Data

 

 

 

 

 

Consumed Data =
VAR _mb =
    CALCULATE (
        SUM ( Fact_App_usage[ConsumedData] ),
        Fact_App_usage[Date] <= TODAY ()
    )
VAR _gb =
    DIVIDE ( _mb, 1000 )
RETURN
    _gb

 

 

 

 

 

Create a new measure called Dynamic TopN Measure

 

 

 

 

 

Dynamic TopN Measure =
VAR _range = [Range Value]
VAR _byUser =
    // Calculating the Top Users based on _range value and Consumed Data
    CALCULATE (
        [Consumed Data],
        KEEPFILTERS ( TOPN ( _range, ALLSELECTED ( Dim_User ), [Consumed Data], DESC ) )
    )
VAR _byApp =
    // Calculating the Top Apps based on _range value and Consumed Data
    CALCULATE (
        [Consumed Data],
        KEEPFILTERS ( TOPN ( _range, ALLSELECTED ( Dim_App ), [Consumed Data], DESC ) )
    )
VAR _result =
    // identifying the selected dimension from the field paramter and switching the result
    SWITCH (
        SELECTEDVALUE ( 'Dynamic Dimension'[Metric], "AppName" ),
        "AppName", _byApp,
        "UserName", _byUser
    )
RETURN
    _result
/*The [Consumed Data] measure may be substituted with an alternative measure, provided that the selected measure is capable of interacting with the chosen dimension.*/

 

 

 

 

 

 

The Dynamic Dimension field may now be dragged into the X-axis of the Bar visual, while the newly created measure (Dynamic TopN Measure) may be placed into the Y-axis.

nandukrishnavs_5-1691495190315.png

 

Interaction with the Range and Dynamic Dimension slicers is now possible. The visual will be updated accordingly, based on the selections made. Just ensure the slicer configuration is same as the below screenshot.

 

nandukrishnavs_6-1691496318954.png

 

nandukrishnavs_7-1691496386293.png

 

I trust that this article has been informative and valuable to you. Your feedback is important to me and I welcome any comments you may have. 😊

 

Thank You 😎



Source link

Be the first to comment

Leave a Reply

Your email address will not be published.


*