Forum Discussion

tonysantangelo's avatar
tonysantangelo
Frequent Visitor
3 years ago
Solved

Histogram with Dynamic Bins

I have a table with a granularity of one row per event. It looks something like this: I would like to create a histogram where the x-axis is number of events and the y-axis is the number of de...
  • v-yueyunzh-msft's avatar
    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