cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper IV
Helper IV

Age and Age intervals, 3 questions

I have a field "birtyday" and i want the age as a field. to make this work, i do the following in power query:

 

* select field birthday

* transform -> date --> age

* transform --> duration --> Total years.

 

this gives me something like 43,63322 etc

 

three questions:

 

* how do i get 43 instead of 43,6332? i dont want to round it to 44. i dont see a data type for this

* is this the most efficient way to calculate the age?

 

* after this age caculcation, i want to put the record in a bucket field. so let's say age range : 40-50. How can i do this? This range should not have a 10 interval, but can be different.

so the output should add a column:

 

10 : < 18

30 : 30-39

44 : 40-59

65 : 60 >

 

Thank in advanced

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User IV
Super User IV

Re: Age and Age intervals, 3 questions

For the first question, you can use Number.RoundDown

https://msdn.microsoft.com/en-us/library/mt253362.aspx

 

You could then use an IF statement in a custom column (DAX) to get your buckets. Works just like Excel IF statement. Probably a way to do it in M as well.

 

 


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Highlighted
Super User IV
Super User IV

Re: Age and Age intervals, 3 questions

For the first question, you can use Number.RoundDown

https://msdn.microsoft.com/en-us/library/mt253362.aspx

 

You could then use an IF statement in a custom column (DAX) to get your buckets. Works just like Excel IF statement. Probably a way to do it in M as well.

 

 


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Highlighted
Microsoft
Microsoft

Re: Age and Age intervals, 3 questions

Hi @amien,

 

To round the numbers, you can go to Transform tab, select "Round Down" under Rounding dropdown list.

 

Capture44.PNG

 

Calcualting the age within POWER BI DESKTOP is more efficient because you don't need to process the age calculation query execution. You can also calculate the age with DAX into a new calculated column.

 

To give the range status for each age value, there's no efficient way to achieve it. Since there's no CASE statement in DAX, you have to nested IF() to apply the range condition for each age.

 

Regards,

Highlighted
Helper IV
Helper IV

Re: Age and Age intervals, 3 questions

Thanks both

Highlighted
Advocate II
Advocate II

Re: Age and Age intervals, 3 questions

Highlighted
Advocate III
Advocate III

Re: Age and Age intervals, 3 questions

I'd say this is the best solution to calculate Age today:

 

 

Age (Today) = FLOOR(IF('Person'[Date Of Birth] < TODAY(), DATEDIFF('Person'[Date Of Birth], TODAY(), DAY) / 365.25, 0), 1)

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors