Forum Discussion
Grouping by age
Morning all,
I thought I'd get a bit of time in Power BI this lovely Saturday morning. I clearly live the rock and roll lifestyle ;-)
I have a list of queries for which I have created a measured column to calculate how old they are in days. What I'd like to do now is create a seperate column which categories them into 4 age brackets:
0-5 Days
6-20 Days
21-50 Days
>50 Days
All help and assistance appreciated.
10 Replies
- OwenAugerSuper User
Hi Anonymous
Static Segmentation is probably the way to go, if you want to assign each row of your table to a group:
http://www.daxpatterns.com/static-segmentation/
Regards,
Owen
- AnonymousNot applicable
Thanks. That looks like exactly what I need.
Struggling to get it working though.
I have created a new table: Age Profile Ranges
Age Range Name
Max
Min
I then create a new calculated column under my existing table 'Current' and I'm trying to amend this expression to suit:
[Price Range] =CALCULATE (VALUES ( Ranges[Price Range] ),FILTER (Ranges,Sales[Price] >= Ranges[Min Price]&& Sales[Price] < Ranges[Max Price]So VALUES ( Ranges[Price Range] would be 'Current'[Incident Age (Days]? This is the column that calculates the age of an incident.Sales[Price] would be 'Current'[Incident Age (Days]?Ranges[Min Price] would be 'Age Profile Ranges'[Min]Sales[Price] is that the age again?Ranges[Max Price] would be 'Age Profile Ranges'[Max]Sorry to be a pain.- SeanCommunity Champion
Anonymous
It seems you have it right? Are you getting an error or...?
Age Range = CALCULATE ( VALUES ( 'Age Profile Ranges'[Age Range Name] ), FILTER ( 'Age Profile Ranges', 'Current'[Incident Age (Days)] >= 'Age Profile Ranges'[Min] && 'Current'[Incident Age (Days)] < 'Age Profile Ranges'[Max] ) )Alternatively you can create a COLUMN in your 'Current' table and use a SWITCH to create your groups like this...
Age Range ALT = SWITCH ( TRUE (), 'Current'[Incident Age (Days)] >= 0 && 'Current'[Incident Age (Days)] <= 5, "0-5 Days", 'Current'[Incident Age (Days)] > 5 && 'Current'[Incident Age (Days)] <= 20, "6-20 Days", 'Current'[Incident Age (Days)] > 20 && 'Current'[Incident Age (Days)] <= 50, "21-50 Days", ">50 Days" )That should do it also! :smileyhappy: