Forum Discussion
Histogram with Dynamic Bins
- 3 years ago
Hi , tonysantangelo
According to your description, On your X axis, you want to put the minimum to maximum number of events where the deviceid exists, and then display the number of devices corresponding to the corresponding number on the Y axis.
Here are the steps you can refer to :
(1)My test data is the same as yours.(2)We can click "New Table " to create a table as x-axis value:
X-axis = var _max_count= MAXX( SUMMARIZE( 'Table' ,'Table'[DeviceId] , "count" , COUNT('Table'[EventId])) , [count]) return GENERATESERIES(1,_max_count,1)(3)Then we can create a measure :
Measure = var _t = SUMMARIZE( 'Table' ,'Table'[DeviceId] , "count" , COUNT('Table'[EventId])) var _max_value = MAXX(_t,[count]) var _min_value = MINX(_t , [count]) var _count = MAX('X-axis'[Value]) var _value = COUNTROWS( FILTER(_t, [count]=_count)) return IF(_count>=_min_value && _count<= _max_value ,_value+0, BLANK() )(4)Then we can put the fields we need on the visual and we can meet your need:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi , tonysantangelo
According to your description, On your X axis, you want to put the minimum to maximum number of events where the deviceid exists, and then display the number of devices corresponding to the corresponding number on the Y axis.
Here are the steps you can refer to :
(1)My test data is the same as yours.
(2)We can click "New Table " to create a table as x-axis value:
X-axis = var _max_count= MAXX( SUMMARIZE( 'Table' ,'Table'[DeviceId] , "count" , COUNT('Table'[EventId])) , [count])
return
GENERATESERIES(1,_max_count,1)
(3)Then we can create a measure :
Measure = var _t = SUMMARIZE( 'Table' ,'Table'[DeviceId] , "count" , COUNT('Table'[EventId]))
var _max_value = MAXX(_t,[count])
var _min_value = MINX(_t , [count])
var _count = MAX('X-axis'[Value])
var _value = COUNTROWS( FILTER(_t, [count]=_count))
return
IF(_count>=_min_value && _count<= _max_value ,_value+0, BLANK() )
(4)Then we can put the fields we need on the visual and we can meet your need:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Awesome work! I think I need to get better at using SUMMARIZE in the future. I made some tiny tweaks for my final measure. When I sliced by Mode my histogram didn't include number of devices with 0 events, which there are no such devices until I slice. I changed the X-axis table definition to start at 0 instead of 1. Then I noticed that the y-axis measure didn't respond to me binning the X-axis values. I followed this article to tweak the y-axis measure accordingly. https://radacad.com/dynamic-banding-or-grouping-in-power-bi-using-dax-measures-choose-the-count-of-bins