Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
j_gan2022
Frequent Visitor

Dynamic Slicer & Histogram

Hi I wanted to create a histogram that is dynamic changes based on my slider.

The Histogram shows the distribution of attendances of students based on Last X Days(Slicer).
The Attendance date for a student can be duplicated for a single date (different course).

I can do it based on a fixed duration. eg Last 30 days.

 

1) SUMMARIZE(MY_TABLE, MY_TABLE[Student_ID], "Number of Attendance", COUNTROWS(MY_TABLE))

2) Create visualization based on the count of counts.

 

j_gan2022_0-1644292433624.png

 

however I can't use a what-if slicer to dynamically change my table based on X Days in step 1)

Your advise is appreciated.

This is my data.

Student IDAttendance Date
120/Jan/2022
220/Jan/2022
120/Jan/2022
221/Jan/2022
221/Jan/2022
321/Jan/2022
321/Jan/2022
422/Jan/2022
322/Jan/2022
422/Jan/2022
1 ACCEPTED SOLUTION

Hi @j_gan2022 

 

The first thing to note is that tables created by new table cannot interact with the slicer in the page, in other words, the table is created statically.

In other words, the table is created statically, so we can only create tables in measure to make them dynamic.

The first step is to prepare the x-axis and what if slicer (last n day table)

X-axis = GENERATESERIES(0,200)

The second step is to create a measure like the one below.

Measure =
VAR _what_if_n_day =
    SELECTEDVALUE( 'Last n day'[Last n day] )
VAR _last_day =
    TODAY()
VAR _last_n_day_table =
    FILTER( 'MY_TABLE', [Attendance Date] >= _last_day - _what_if_n_day )
VAR _summarize =
    SUMMARIZE(
        _last_n_day_table,
        [Student ID],
        "Number of Attendance", COUNTROWS( 'MY_TABLE' )
    )
RETURN
    COUNTROWS(
        FILTER(
            _summarize,
            [Number of Attendance] = SELECTEDVALUE( 'X-axis'[Value] )
        )
    )

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

4 REPLIES 4
j_gan2022
Frequent Visitor

Need help on this. Thanks

Hi @j_gan2022 

 

The first thing to note is that tables created by new table cannot interact with the slicer in the page, in other words, the table is created statically.

In other words, the table is created statically, so we can only create tables in measure to make them dynamic.

The first step is to prepare the x-axis and what if slicer (last n day table)

X-axis = GENERATESERIES(0,200)

The second step is to create a measure like the one below.

Measure =
VAR _what_if_n_day =
    SELECTEDVALUE( 'Last n day'[Last n day] )
VAR _last_day =
    TODAY()
VAR _last_n_day_table =
    FILTER( 'MY_TABLE', [Attendance Date] >= _last_day - _what_if_n_day )
VAR _summarize =
    SUMMARIZE(
        _last_n_day_table,
        [Student ID],
        "Number of Attendance", COUNTROWS( 'MY_TABLE' )
    )
RETURN
    COUNTROWS(
        FILTER(
            _summarize,
            [Number of Attendance] = SELECTEDVALUE( 'X-axis'[Value] )
        )
    )

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

@j_gan2022 , There is a histogram visual, have you tried that. Search on app store. There should be one from Microsoft , try that.

 

A calculated table can not use slicer values.

 

Better to create dynamic segmentation

https://www.daxpatterns.com/dynamic-segmentation/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak , I have completed on the histogram.
However, I couldnt understand the dynamic segmentation. Could you give a starting code for me to follow up? Thanks

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.