Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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
Solved! Go to Solution.
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.
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
Hi @amien,
To round the numbers, you can go to Transform tab, select "Round Down" under Rounding dropdown list.
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
The link might be helpful:
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.
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.