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
ktt777
Helper V
Helper V

conveting text and number in age calculation

hi,

how can i use dax formula to create column Age with data type as decimal  and the value is blank if the data in Birthday column is blank

then how to calculate average to exclude zero or null ?

 

NameBirthday Age
A1/1/20221.17
B  
C1/12/20220.25

 

thanks

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @ktt777 ,

You can create a calculated column as below to get it:

Age = DIVIDE ( DATEDIFF ( 'Table'[Birthday], DATE ( 2023, 3, 19 ), MONTH ), 12 )

vyiruanmsft_0-1680159578991.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @ktt777 ,

You can create a calculated column as below to get it:

Age = DIVIDE ( DATEDIFF ( 'Table'[Birthday], DATE ( 2023, 3, 19 ), MONTH ), 12 )

vyiruanmsft_0-1680159578991.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ppm1
Solution Sage
Solution Sage

FYI that the Power Query editor has an Age function on the Add Column tab. That will create a duration column in days you can conver to Total Years. You can then use a measure like this to get the average.

 

AgeMeasure = CALCULATE(AVERAGE(Person[Total Years]), Person[Total Years] <> 0)
 
Alternatively, you can avoid adding an extra column at all and just use a measure to calculate it.
 
AgeMeasure2 =
CALCULATE (
AVERAGEX ( Person, INT ( TODAY () - Person[Birthdate] ) / 365 ),
NOT ( Person[Birthdate] IN { TODAY (), BLANK () } )
)
 
Pat
Microsoft Employee
YukiK
Impactful Individual
Impactful Individual

Use a formula like this:

Your Column = DIVIDE( DATEDIFF ( BIRTHDAYCOLUMN, TODAY (), DAY ), 365 )

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.