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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Calcular edad entre fecha dada y la fecha actual

Hola, requiero de su ayuda para crear una columna personalizada en Power Query que me calcule la edad en años y meses, dando como parámetros una fecha de nacimiento y la fecha actual.

Ejemplo:

Fecha de nacimiento: 15/04/2018

Fecha Actual: 18/05/2020

Edad 7 años 7 meses

En Excel utilizaría la fórmula =sifecha(hoy();a1;"y") & " " & sifecha(hoy();a1;"m")

Pero en Powerquery sé que se puede utilizar una fórmula como Duration.Days..... pero no sé cómo hacerlo

 

Muchas gracias.

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

Hi @Anonymous 

Create a query, then invoke the query into your table

Capture6.JPGCapture7.JPG

(yourdate as date)=>
let
    startdate=
    if yourdate>Date.From(DateTime.LocalNow()) then null else yourdate,
    MyYears=Number.RoundDown(Duration.TotalDays(Date.From(DateTime.LocalNow()) - startdate)/365),
    month1=Date.Month(Date.From(DateTime.LocalNow()))-Date.Month(Date.AddYears(startdate,MyYears)),
    mymonths=if month1<0 then 12+month1 else month1,
    Concat = 
    Text.From(MyYears) & " Yrs " & 
    Text.From(mymonths) & " Months"
in
    Concat

 

Best Regards
Maggie
Community Support Team _ Maggie Li
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

5 REPLIES 5
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create a query, then invoke the query into your table

Capture6.JPGCapture7.JPG

(yourdate as date)=>
let
    startdate=
    if yourdate>Date.From(DateTime.LocalNow()) then null else yourdate,
    MyYears=Number.RoundDown(Duration.TotalDays(Date.From(DateTime.LocalNow()) - startdate)/365),
    month1=Date.Month(Date.From(DateTime.LocalNow()))-Date.Month(Date.AddYears(startdate,MyYears)),
    mymonths=if month1<0 then 12+month1 else month1,
    Concat = 
    Text.From(MyYears) & " Yrs " & 
    Text.From(mymonths) & " Months"
in
    Concat

 

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

Anonymous
Not applicable

Muchas gracias.

Pero tengo una inquietud: Esta misma solución aplica para Power Query de Excel (lenguaje M)?
Porque la solución que me brindó es para Lenduaje DAX de Power Bi.

Anonymous
Not applicable

Excelente. Gracias

Anonymous
Not applicable

Muchas gracias.

Voy a intentar

edhans
Super User
Super User

If you will post this in the spanish group, it may translate it back to English for this group. The translation feature doesn't work when it is Spanish in the English forum.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors