Age Calculation

Age Calculation in Power BI using Power Query

Power Query has a simple approach that provides a simple method for calculating the age. However, because DAX is the most used language usedin several calculationsin Power BI, many don't know about the function available in Power Query. In this blog post, I'll explain how easy the process is calculateAge with Power BI using PowerBI. This methodis very beneficial in situations where it is required to perform the age calculationcan be calculated by calculating the age on a row by row basis.

Calculate Age from a date

This is an example of the DimCustomer Table, that is part of the AdventureWorksDW table that acts as the birthdate column. I've eliminated columns that aren't required for clarity;

To calculate the age of every buyer, you need is:

  • In Power BI Desktop, Click on Transform Data
  • In the Power Query Editor window; make sure to choose the first column, namely the Birthdate.
  • To add columns, click on the Column Tab and click on the Add Column Tab, which is within the "From Date & Time" section. Then, under Date, choose Age

It's that simple. it. It will calculate any variations between that column, the Birthdate column, and the current date and time.

However, the age that you see when you look into the Age column, doesn't seem like an actual age. It's because it's an actual Duration.

Duration

Duration is a distinct type of data that is utilized in Power Query which represents the differences between two DateTime values. Duration can be described as a mixture of four different values:

days.hours.minutes.seconds

That's what you'll discover in the details above. However, from users' standpoint, they shouldn't have to look up information as detailed in the above. There are methods you can use to find each element of the time. If you select the Duration menu you'll see that you can pull the total amount of minutes, seconds, hours, days , and even years from it.

To aid in calculating the age in years for instance it is easy to hit the Total Year:

Notice that the duration was measured in days . It was then divided into 365 days to produce the annual sum.

Rounding

It's the truth, no one states an age for their children as 53.813698630136983! They say 53, which is an rounded down. It's very easy to select Rounding and then round down by selecting the Transform tab for it.

This will give you the year-old number:

You can then tidy other columns as you'd like (or there's a possibility that you have applied transformations using the Transform tab to avoid creating new columns) You can also name this column Age.

Things to Know

  • Refresh The age that is calculated this way will get modified at the time of refreshing your database. Every time, it will match the birthdate with the date and time that the data refresh occurred. This method is a way to calculate earlier of age. If, however, you'd like the calculation to be performed dynamically, using DAX This is the way I've described the best way to use.
  • The motivation behind Power Query: Benefits of performing an age calculation with Power Query is that the calculation is carried out after you refresh the report. The calculation is performed using an algorithm that makes the calculation more easy to do, and there won't be additional work involved in doing it with DAX for a measurement of runtime.
  • Different scenarios This is not intended to be used to calculate the age of a person based on their birth date. This could be used to calculate product inventory age and the distinct dates and dates from each other.

Video

REZA RAD

TRAINER, CONSULTANT, MENTORReza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has an BSc with a major in Computer engineering. He has more than 20 years of experience in data analysis as well as database programming, BI and development generally making use of Microsoft technologies. He has been an Microsoft Data Platform MVP for nine consecutive years (from 2011 until now) due to his dedication to Microsoft BI. Reza is a regular blog writer, and also the co-founder and editor of RADACAD. Reza is also co-founder and the co-organizer of Difinity the conference which takes place within New Zealand.
His articles on different aspects of technologies, especially on MS BI, can be found on his blog: https://radacad.com/blog.
He co-authored several books on MS SQL BI and also is writing other books. He also was a regular participant in online forums for technical issues , such as MSDN and Experts-Exchange and was moderator on the MSDN SQL Server forums, and is an MCP , Microsoft Certified Specialist (MCSE) as well an MCITP in BI. He was the creator of the New Zealand Business Intelligence users group. In addition, he's also an author of the extremely popular workbook Power BI from Rookie to Rock Star, which is offered for free and features more than 17000 pages of information and Power BI Pro Architecture, which is the Power BI Pro Architecture published by Apress.
It 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 aim is to help you find the ideal solutions for data. He's a Data enthusiast.This entry was posted on the topic of Power BI, Power BI from Rookie to Rockstar, Power Query and included in Power BI, Power BI from Rookie to Rock Star, Power Query. This is an excellent resource to bookmark.

Post navigation

Share various visual pages using different Security Groups in Power to use BIAge's Calculation of Years that is used for Leap Year in Power BI by using Power Query

Comments

Popular posts from this blog

Random Number Generator

scientific and graphing calculators

digital-converter