Age Calculation in Power BI using Power Query
Power Query has a simple method in calculating the age. However, because DAX is the most popular languagein various analysesin Power BI, many do not know about the option available within Power Query. In this post, I'm going to show you how simple it is to calculateAge in Power BI, using Power BI. This methodis extraordinarily effective in situations where the Age calculationcan be carried out on an already calculated row-by-row basis.
Calculate Age from a date
It's the DimCustomer table of the AdventureWorksDW table which as a birthdate column. I've removed some of the columns that aren't needed for easier reading;
If you'd like to calculate the age of every 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. Under "From Date & Time" section, then under Date Choose the appropriate age range.
That's all there is to it. It can calculate an amount which is the sum of the Birthdate column, as well as the current date and hour.
However, the number you can see in the Age column, doesn't appear to be an actual age. It's because it's a time.
Duration
Duration is an exclusive data type used on Power Query which represents the difference between the two DateTime values. Duration is a mixture of four different values:
days.hours.minutes.seconds
This is how you take the information above into consideration. But from a user's point of view, you don't want them to look up information like this. There are ways to extract each element from the length. If you choose the Duration menu it will show you can get the number of seconds days, minutes, days, and years from it.
To use this method for calculating the age in years such as you simply go to Total Years.
Take note that the duration that the programme runs is measured in days . Then, it is divided by 365, which will give you the year-long value.
Rounding
At the final point, there is no consensus that says that the Age is 53.813698630136983! They are referring to it as 53, and rounding it down. You can select Rounding as well as Round Down under the Transform tab for it.
This will provide you with the age in years:
Then , you can clean the other columns, if desired (or maybe you've performed transformations with the Transform tab to prevent the new columns) Then name the column with the following: Age
Things to Know
- Refresh: The age calculated through the method gets refreshed during the process the database refresh occurs. Each time, it will match your date of birth with the date and the date the data refresh took place. The method will provide an older calculation for age. If you want calculations of the age to take place quickly using DAX Here I have explained the methods you can use.
- How to use Power Query: Benefits of making age calculations with Power Query are that the calculations are made as you refresh your report. This is done by making use of an instrument that makes the calculation more simple, and it won't be additional work involved in doing the calculation using DAX in order to determine runtime.
- Additional scenarios an accurate method of calculating age on the basis of birth date. This is a fantastic way to determine product inventory and for the differences between two dates or dates each other.
Video
REZA RAD
TRAINER, CONSULTANT, MENTORReza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has a BSc from Computer engineering. There are more than 20 years' working experience in data analysis database, BI, programming and development primarily based on Microsoft technologies. He has been named an official Microsoft Data Platform MVP for nine consecutive years (from 2011 until now) because of his dedication to Microsoft BI. Reza has been a prolific author and co-founder at RADACAD. Reza is also co-founder as well as co-chairman of Difinity conference 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 has published a number of book in the field of MS SQL BI and also is working on a few additional. He was also a regular participant in online forums for technical matters like MSDN Experts-Exchange as well as the moderator of MSDN SQL Server forum with the MCP as well as MCSE certifications as well as an MCITP in BI. He is the coordinator of the New Zealand Business Intelligence users group. Also, he is the writer of the book popularly praised Power BI from Rookie to Rock Star, which is free and has hundreds of pages of material in addition to The Power BI Pro Architecture published by Apress.
He 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 goal is to help users find the best data solution. He is an avid Data enthusiast.This article was released under Power BI, Power BI from Rookie to Rockstar, Power Query and included in Power BI, Power BI from Rookie to Rock Star, Power Query. The following is a great resource to bookmark.
Post navigation
Share Different Visual Pages with different Security Groups Power BI's Age Calculation that is able to calculate the Leap Year in Power BI with Power Query (see below).
Comments
Post a Comment