Age Calculation

Age Calculation in Power BI using Power Query

Power Query has a simple way of calculating the age. But, since DAX is the popular language usedin numerous functionsin Power BI, many do not know about this function in Power Query. In this blog post I will describe how simple it is to calculateAge in Power BI using Power BI. The methodis extremely useful in situations where the estimation of the agecan be carried out on an already calculated row-by-row basis.

Calculate Age from a date

The table below is DimCustomer table , which is from the AdventureWorksDW table, which acts as an age column. I've removed a few of the columns that aren't needed to make it easier to read.

In order to calculate the age of each customer, all you have to do is:

  • In Power BI Desktop, Click on Transform Data
  • In the Power Query Editor window; select the Birthdate column first
  • Click on the Add Column Tab, and then click on the "From Date & Time" section, and then under Date, select the age range.

That's it. this calculates the calculate what's the ratio between Birthdate column, and the current date and time.

But, the age you see when you look at the Age column, doesn't appear like an age. This is because it's a Duration.

Duration

Duration is a distinct form of data of data type in Power Query which represents the distinction between two DateTime values. Duration is a mixture of four values:

days.hours.minutes.seconds

and that's how you can read the above values. However, from an individual's perspective they shouldn't be expected to read specifics like this. there are ways that you can fetch each part in the period. Utilizing the Duration menu, you will see that you can extract the number of seconds, minutes, hours days, and years from it.

To use the method of calculating the age in years for instance, you can simply click on Total Years:

Note that the duration is calculated in days . It is afterwards divided into 365 to yield the yearly amount.

Rounding

In the end, nobody is claiming they are 53.813698630136983! They refer to it as 53, and then round it down. You can select Rounding option and then round down on the Transform tab.

This will provide you with the number in years:

Clean up the other columns, if you wish (or the possibility is that you used transformations on the Transform tab to avoid making new columns), and call this column: Age.

Things to Know

  • Refresh: The age calculated this way will be updated at the time of refreshing your data. Every time, the system will be able to compare the date of birth with the date and date that the data refresh took place. This method is a pre-calculation of the age. If you require the calculation of age to be dynamically done using DAX here is how I described an approach you can use.
  • Why Power Query: Benefits of using age calculation with Power Query is that the calculation is performed at the time of refreshing your report. You use an instrument that makes the calculation more simple, and there's no need for the extra expense of doing it with DAX as a measure of runtime.
  • Other scenarios This is not meant to calculate age only starting with the birth date. This can be used to calculate product inventory and for the differences between two dates and times from one another.

Video

REZA RAD

TRAINER, CONSULTANT, MENTORReza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has been awarded a BSc of Computer engineering. He holds more than 20 years' experience in data analysis database, BI, programming, and development mostly in Microsoft technologies. He has been a Microsoft Data Platform MVP for nine years in a row (from 2011 till now) for his dedication in Microsoft BI. Reza is a prolific journalist and co-founder for RADACAD. Reza is also co-founder as well as co-organizer for the Difinity conference at 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 some others, He was also an active member on online technical forums such as MSDN and Experts-Exchange as well as the moderator for MSDN SQL Server forums, and is an MCP and MCSE as well as an MCITP in BI. He is the head of the New Zealand Business Intelligence users group. Also, he's the author of the highly popular book Power BI from Rookie to Rock Star, which is available for free and has more that 1800 pages of material and Power BI Pro Architecture, which is the Power BI Pro Architecture published by Apress.
The speaker is an International Speaker in 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 goal is to help you find the best data solution, he is Data enthusiast.This post was filed by Reza in Power BI, Power BI from Rookie to Rockstar, Power Query and included in Power BI, Power BI from Rookie to Rock Star, Power Query. Bookmark the permalink.

Post navigation

Share different visual pages using different security groups in Power BIAge's Year Calculation that is used for Leap Year in Power BI with Power Query

Comments

Popular posts from this blog

All Vegetables Name In English

Birds Name in english

What Is a Calorie?