Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
amien
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
Greg_Deckler
Super User
Super User

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!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

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)

 

hi I know this post already has a solution but I was wondering if you could explain how this dax formula works? I know FLOOR rounds a number down close to 0 but if you could explain for your formula, that would be great

v-sihou-msft
Employee
Employee

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,

Thanks both

Greg_Deckler
Super User
Super User

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!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors