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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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