Forum Discussion
Dynamic Bins Size by Parameter
Hello I tried to find the Percentage of Churns by Age (Bins). I want to chaneg the age bin size by parameter.
power bi file link:
https://drive.google.com/drive/folders/1YhZZ1csw_dHjBpND9uCTsEraDia47Jmc?usp=sharing
In Tableau its easy to chaneg the size of bins by parameter but here I didn't find a way. anybody here can help please ?
Now the size is 1, i want to chaneg the bin size by parameter.
7 Replies
- indkittyHelper II
Hi Fahadqadir,
Dynamic Banding or Grouping in Power BI - Using DAX Measures - Choose the Count of Bins - RADACAD
Dynamic BandingCould you look into Radacad solution. I believe this should solve your issue.
Let me know.
- fahadqadirHelper I
Yes, I use this approach but I don't know how I add my Percentage churn measure to the calculation to find % churn by dynamic bin size.
- MigasukeMemorable Member
Hi,
I really like solution which indkitty posted. It basically avoid the problem with dynamic columns in a table.
This solution seems to be better than the M parameter. In case you need % distribution I edited measure Radacad has.Count of Customers in each Band = var _minAge=[Min Age] var _maxAge=[Max Age] var _bandSize=[Band Size Value] var _AgeBandTable=GENERATESERIES(_minAge,_maxAge,_bandSize) var _currAge=SELECTEDVALUE('Age Band'[Age]) var _bandHead=MAXX( FILTER( _AgeBandTable, [Value]<=_currAge),[Value]) var _bandTail=_bandHead+_bandSize var _allNumber = CALCULATE(COUNTROWS(DimCustomer),ALL(DimCustomer)) var _numberCount = if(_currAge=_bandHead, CALCULATE( COUNTROWS(DimCustomer), 'Age Band'[Age]>=_bandHead && 'Age Band'[Age]<_bandTail )) return DIVIDE(_numberCount,_allNumber)Basically I created a variable, where I calculate ALL people and in return statement I divide it (to get %).
Result looks like this:
- MigasukeMemorable Member
Hi fahadqadir ,
depends which parameter you want to use.
DAX doesn't support dynamic calculate columns. Theoreticaly you could open your model in Tabular editor and find your group. Since calculated group is just a DAX code, you might find something which looks like this (my Groups for Age):I can set up, that the values 5 (which determines size of my group) is taken from a measure / slicer, but then the group (calculated column) stops working.
Instead you can use M query parameter. This solution is not that user friendly, but you can create calculated column in Power Query. Disadvantage is, that your table needs to be reloaded every single time you change the parameter. So in case you deal with milions of rows, its not really convenient.
In case you would like to try the Power Query approach, let me know.- MigasukeMemorable Member
Actually there might be one more option and that would be having hierarchy in your data.
For example, you predefine groups with size 1-5-10 and then you can drill down/drill up in your visuals from 1 up to 10. But again there is some downsize that in case you want to have custom size like 20, it wont be available in your drill down/up option. - fahadqadirHelper I
I try Power Query approach by creating 2 new tables, one by parameter and other for calculations and relate to the data. but Calculations not working as expected.
- fahadqadirHelper I
Can you please share the best way to find the percentage churn by dynamic bins (As I select the bin size through parameter, like bin size 2, 3, 5 or 10....