Age Calculation

Age Calculation in Power BI using Power Query

Power Query has a simple method for calculating the age. However, since DAX is the primary language usedin numerous calculationsin Power BI, many are not aware of this feature of Power Query. In this article, I'll demonstrate how simple it is calculateAge within Power BI using Power BI. It is a methodis extremely useful in situations where your estimation of the agecan be done as an earlier calculated row by row basis.

Calculate Age from a date

Below you can see the DimCustomer table, which is comprised of AdventureWorksDW table which functions as the birthdate column. I've removed several of the extra columns to make it easier to read.

In order to calculate your the age of each customer the only thing you need to do is:

  • In Power BI Desktop, Click on Transform Data
  • In the Power Query Editor window; pick the first column for the Birthdate column.
  • go to add Column Tab, and then click on"Add column tab," and click the "From Date & Time" section, and under Date, choose Age

That's that. This is how you calculate an amount which is the total of the Birthdate column, in addition to the current date and time.

The age, however, which appears in"under" the Age column, however, it does not appear to be the actual age. It's because it's actually a duration.

Duration

Duration is a distinct data type within Power Query which represents the variation between the two DateTime values. Duration is a combination of four numbers:

days.hours.minutes.seconds

This is how you look at the data. But, from the point of view of the user it is not their responsibility to look up the entire details of this. There are methods that could be able to get every component of the period. By selecting the Duration menu, you will see that you are able to determine the number of seconds and minutes, hours, days and years out of it.

To assist with calculating the age in years for example you simply press Total Year:

Be aware that the duration is measured in days . Then, it is multiplied by days, for the year's total.

Rounding

There is no truth in it, and no one says they're 53.813698630136983! They use the word 53 which is reduced to a round number. It's simple to choose Rounding and round down from the Transform tab.

This will reveal how old you are:

Then, you can clean the other columns, if desired (or perhaps you've made use of transformations through the Transform tab to avoid having to create new columns) And name this column: Age

Things to Know

  • Refresh The age that is calculated this way will be refreshed every time you're refreshing your information. Each time, it compares dates of birth with the date and time at the time of refresh. This method is an algorithm for pre-calculating an age. If, however, you need the calculation to be dynamically done using DAX here is how I described the method you could apply.
  • The reason behind Power Query: Benefits of performing an age calculation using Power Query is that the calculation takes place during the refresh of your report. This is done using an instrument which makes the calculation easier and faster, and there is no additional overhead when it is calculated using DAX for measuring runtime.
  • Alternative scenarios It is not utilized to calculate the age of a person based on their birth date. This is a good way to determine inventory-level ages for inventory items and also to determine the difference between two dates and dates from one another.

Video

REZA RAD

TRAINER, CONSULTANT, MENTORReza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He holds a BSc in Computer engineering. He has more than 20 years old. experience in the field of data analysis and databases, BI and development, mostly using Microsoft technologies. He is an official Microsoft Data Platform MVP for 9 consecutive years (from 2011 until the present) because of his enthusiasm to Microsoft BI. Reza is a prolific blog writer, and the co-founder and director of RADACAD. Reza is also co-founder as well as co-organizer for Difinity Conference. Difinity Conference located in New Zealand.
His articles on different aspects of technologies, especially on MS BI, can be found on his blog: https://radacad.com/blog.
He wrote several books on MS SQL BI and also is writing more books. He was also a frequent participant in forums online for technical issues like MSDN and Experts-Exchange and was also the moderator of MSDN SQL Server forums, and is an MCP and MCSE and an MCITP of Business Intelligence. He is the leader in the New Zealand Business Intelligence users group. In addition, he is the creator of the highly acclaimed workbook Power BI from Rookie to Rock Star, which is completely free with over 170 pages of content. The Power BI Pro Architecture published by Apress.
It is an International speaker at Microsoft Ignite, Microsoft Business Applications Summit, Data Insight Summit, PASS Summit, SQL Saturday and SQL users groups. And He is a Microsoft Certified Trainer.
Reza's passion is to help users find the best data solution. He is an avid Data enthusiast.This blog post has been published by Reza in Power BI, Power BI from Rookie to Rockstar, Power Query and is filed in Power BI, Power BI from Rookie to Rock Star, Power Query. This entry was filed under Power BI. The following entry was filed under Power BI.

Post navigation

- Share different visual pages using different security groups in Power BIAge's Years Calculation which works for Leap Year in Power BI through Power Query

Comments

Popular posts from this blog

angle-converter

BMI Calculator

scientific calculator