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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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!:
Mastering Power BI 2nd Edition

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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.