Forum Discussion

vikash_X_Sinha's avatar
vikash_X_Sinha
New Member
8 months ago
Solved

Dynamic Buckets based on slicer

Hi All,   I am currently working on Dynamic buclet based on slicer. i have created calculated column and used selectedvalue to select the slicers which are bin size, Max bin and Min bin. But it is ...
  • Anonymous's avatar
    Anonymous
    8 months ago

    Hi vikash_X_Sinha ,

    Thank you for reaching out to the Microsoft Fabric Community Forum.

     

    Dynamic buckets cannot be created using calculated columns because calculated columns are evaluated during model refresh and cannot react to slicers. That is why your SELECTEDVALUE() logic does not work.

    To implement dynamic Min/Max/Bin logic, you will need a pre-generated Bucket table (covering the maximum possible bin ranges), and then use measures to calculate the bucket labels and summary values based on slicer selections.

    Create a supporting Bucket table (covers all possible values):

    Buckets =
    GENERATESERIES ( 1, 2000000, 1 )
    ​

    Create a Bucket Range measure: 

    Bucket Label =
    VAR MinBal = SELECTEDVALUE(MinBalance[Value], 0)
    VAR MaxBal = SELECTEDVALUE(MaxBalance[Value], 0)
    VAR Bin = SELECTEDVALUE(BinSize[Value], 0)
    VAR Current = MAX(Buckets[Value])
    
    RETURN
    IF (
        Current >= MinBal && Current <= MaxBal,
        FORMAT( FLOOR((Current - MinBal) / Bin, 1) * Bin + MinBal, "0") 
            & " - " &
        FORMAT( (FLOOR((Current - MinBal) / Bin, 1) * Bin) + Bin + MinBal, "0" ),
        BLANK()
    )
    ​

    Create your value measure (e.g. count or sum): 

    Total Amount in Bucket =
    VAR Label = [Bucket Label]
    RETURN
    IF(NOT ISBLANK(Label), SUM(Fact[Amount]))
    ​

    Place this in your bar chart on X-axis → Bucket Label (measure) and on Y-axis → Total Amount in Bucket (measure) now apply slicers for Min, Max, and Bin Size.

    If it's still doesn't work please share a small sample dataset and the expected bucket output. I can then create the exact DAX and PBIX structure for your scenario.

     

    Thank you.