Forum Discussion

speedramps's avatar
speedramps
Icon for Super User rankSuper User
5 months ago
Solved

Reusable slicer choices logic

See attached PBIX and screen prints which displays the seleted the slicer choices in a handy box.  Click to download PBIX from Onedrive      The standard CONCATENATEX will delimit al...
  • OwenAuger's avatar
    5 months ago

    Hi speedramps,

    I would personally recommend a DAX user-defined function for this (assuming you're happy to use this feature as it is still in preview).

     

    For example, you could create a function that takes two arguments: a column reference and limit. You would then define measures that each pass the required column reference and limit to this function.

     

    As an example, I have rewritten your measures using the below UDF in the attached PBIX (slightly rewritten using variables for some expressions). The main change is that every reference to the column 'Dim Customer'[Customer] (or other column) has been replaced by the function argument Col. Please check the logic is still correct ðŸ™‚

    ( Col: COLUMNREF, Limit: INT64 ) =>
    
    // get a list upto the Limit
    VAR col_list =
        TOPN ( Limit + 1, VALUES ( Col ), Col )
    VAR col_count = DISTINCTCOUNT ( Col )
    
    // get the max item in the column
    VAR col_max = MAX ( Col )
    
    // get the max item in the list of top values
    VAR col_list_max = MAXX ( col_list, Col )
    
    // format the ending text   ( for example " and "    or    " and 5 others"
    VAR col_endtext =
        IF (
            col_count > Limit,
            " and " & col_count - Limit & " others",
            " and " & col_max
        )
    
    // concatenate the list ( for example A, B, C, D, E )
    VAR col_concat =
        IF (
            ISFILTERED ( Col ),
            CONCATENATEX (
                col_list,
                Col,
                ", ",
                Col
            ),
            "ALL"
        )
    RETURN
        // replace the last item in the concatenations with the ending text (for example "A, B, C, D and E"   or  "A, B, C, D and 5 others"
        "= "
            & SUBSTITUTE ( col_concat, ", " & col_list_max, col_endtext )

    The âœ‚ Customer measure would then be:

    ✂ Customer = 
    ColumnSelectionsString ( 'Dim Customer'[Customer], 9 )

    Would something like this work for you?