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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
PatrikSwe
Regular Visitor

Histogram counting number of days within binned values

Hello PBI experts,

 

I am stuck on a problem and can't seem to find the answer here or anywhere else.

 

I need to create a histogram, where the height of each bar shows the number of (distinct) days that there have been various number of visits to a facility. The number of visits are to be divided into bins with fixed intervals. E.g., if the interval size would be 10, the first bar would show how many days there have been 0-9 visits, the 2nd bar would show how many days there have been 10-19 visits, and so on. Similar to the chart below.

 

PatrikSwe_0-1683035658183.png

 

I can't simply solve this by making a calculated bin column, as the chart needs to be sliced by other columns in the table, such as department.

 

For the this sample data:

 

VisitIDDateDepartment
12022-01-01A
22022-01-01B
32022-01-02B
42022-01-02A
52022-01-02B
62022-01-02C
72022-01-02C
82022-01-02C
92022-01-03B
102022-01-03C
112022-01-03A
122022-01-03A
132022-01-03A
142022-01-04B
152022-01-04B
162022-01-04B
172022-01-04B
182022-01-04C
192022-01-04C
202022-01-04C

 

with an interval size of 3, the unfiltered histogram would show 3 bars like this:

 

PatrikSwe_1-1683037598485.png

The summary tables below might make this a bit more clear:

 

DateNumber of visits
2022-01-012
2022-01-026
2022-01-035
2022-01-047

 

Number of visitsNumber of dates (with number of visits within this range)
0-21
3-51
6-82

 

As mentioned, I also need to be able to slice by department. So, for the the sample data, I want the user to be able to select only department A and see what the chart would look like for that department, and so on.

 

My actual data has 750k visits over a period of 3 years and the requested interval for the bins is 10 (0-9, 10-19, 20-29, etc).

 

Any help or pointers in how to solve this issue would be very much appreciated!

1 REPLY 1
Irwan
Super User
Super User

Hello @PatrikSwe ,

 

please check if this match to your need based on your sample data above. Other Power BI expert might have better and elegant solution.

 

1. in your first summarize table, you need to add department column since you want to be able to slice department value. Just add another column for department from what you did.

Irwan_1-1719279484766.png

 

2. follow up in your second summarize table, add department and calculate 'Number of Dates' using conditional if for each 'Number of Visit' for exact same department.

Irwan_2-1719279645864.png

Number of dates =
var _dept = 'Table 3'[Department]
Return
IF(
    'Table 3'[Number of Visit]="0-2",
    COUNTROWS(FILTER(
        'Table 2',
        'Table 2'[Number of Visit]<=2&&
        'Table 2'[Department]=_dept
    )),
IF(
    'Table 3'[Number of Visit]="3-5",
    COUNTROWS(FILTER(
        'Table 2',
        (
            'Table 2'[Number of Visit]>=3&&'Table 2'[Number of Visit]<=5
        )&&
        'Table 2'[Department]=_dept
    )),
IF(
    'Table 3'[Number of Visit]="6-8",
    COUNTROWS(FILTER(
        'Table 2',
        (
            'Table 2'[Number of Visit]>=6&&'Table 2'[Number of Visit]<=8
        )&&
        'Table 2'[Department]=_dept))
)))

 

3. create bar visual with slicer. This slicer has to be department column from your second summarize table since no table-relationship made.

Irwan_0-1719279376714.png

Irwan_3-1719279882412.png

 

Hope this will help you.

Thank you.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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