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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Guneui_Lee
Regular Visitor

How to Dynamically Update Histogram with Slicer in PowerBI

Hello, I have a table with {Date, Product Name, Sales} data. I want to display sales by product name in a histogram with 10 groups of equal intervals. I have successfully created a histogram for the entire period using a vertical bar graph, with groups on the x-axis and the count of dates on the y-axis. I added a column to determine which group (0 to 9) each row belongs to by calculating the minimum, maximum, and interval size.

 

My question is, in Excel, when I create a histogram and filter the Time column, the groups are recalculated and the histogram updates. I want to achieve the same in PowerBI. When I add a slicer to filter dates, I want the histogram to dynamically update for the filtered range. How should I write the DAX formula to achieve this? Thank you.

1 ACCEPTED SOLUTION

[Solution]

I added a table to represent separate groups and set it up by using measure to calculate the number of cases for each group. I've noticed that the histogram is generated dynamically based on the lookup period.

View solution in original post

3 REPLIES 3
Guneui_Lee
Regular Visitor

Thank you for your response.

 

What I want to achieve is a histogram with groups on the X-axis and the count of data within each group on the Y-axis, as shown in the attached histogram. I am calculating the groups based on the min and max, dividing them into 10 groups.

Guneui_Lee_0-1721295465161.png

 

 

With the current DAX formula I have, the histogram does not recalculate and only shows parts of the already calculated groups.

 

GroupNumber =
VAR _SelectedProduct = [Product]
VAR _min = CALCULATE(MINA([Sales]), Sheet1, Sheet1[Product] = _SelectedProduct)
VAR _max = CALCULATE(MAXA([Sales]), Sheet1, Sheet1[Product] = _SelectedProduct)
VAR _range = (_max - _min) / 10   --10 group
VAR _group = INT(([Sales] - _min) / _range)
RETURN IF(_group = 10, 9, _group)

 

 

If I calculate the groups as a measure, it works for the selected time range, but I still cannot use this measure on the X-axis of the vertical bar graph. I need to display the groups as a column. When using the measure as a column, it still calculates for the entire period.

 

 

This is the histogram I want as a result.

Guneui_Lee_1-1721295698197.png

 
I manually set the start time to configure this group I wanted.
 
GroupNumber_Want =
VAR _SelectedProduct = [Product]
VAR _StartDate = DATE(2024, 07, 10)
VAR _min = CALCULATE(MINA([Sales]), Sheet1, Sheet1[Product] = _SelectedProduct, Sheet1[Date] >= _StartDate)
VAR _max = CALCULATE(MAXA([Sales]), Sheet1, Sheet1[Product] = _SelectedProduct, Sheet1[Date] >= _StartDate)
VAR _range = (_max - _min) / 10   --10 group
VAR _group = INT(([Sales] - _min) / _range)
RETURN IF(_group = 10, 9, IF(_group < 0, BLANK(), _group))

 

 

[Solution]

I added a table to represent separate groups and set it up by using measure to calculate the number of cases for each group. I've noticed that the histogram is generated dynamically based on the lookup period.

Anonymous
Not applicable

Hi @Guneui_Lee ,

Based on the testing, the histogram can dynamically update for the date range.

 

vjiewumsft_0-1721293939089.png

You can also view the following document to learn more information.

Solved: Dynamic Slicer & Histogram - Microsoft Fabric Community

 

Best Regards,

Wisdom Wu

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

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.