Age Calculation
Age Calculation in Power BI using Power Query
Power Query has a simple method of calculating the age. However, because DAX is the preferred language usedin many calculationsin Power BI, many don't know about this feature provided by Power Query. In this article, I'll describe how easy it is to calculateAge in Power BI using PowerBI. It is a methodis extremely efficient in cases where the estimation of your agecan be performed on a pre-calculated rows and basis.
Calculate Age from a date
Below, you'll find the DimCustomer table which is part of the AdventureWorksDW table. It also has an entry for birthdates. I've removed several of the columns that don't need to be for ease of read;
To calculate the time of each customer's purchase all you need to do is:
- In Power BI Desktop, Click on Transform Data
- In the Power Query Editor window; begin by selecting the Birthdate column.
- Click on the Add Column Tab, and then select"Add Column Tab," then click on the "From Date & Time" section. Next, under Date select the date range.
That's all there is. This is how you calculate an amount that is the total of the column for birthdate, Birthdate column, and the date and time.
But, the age appears on the Age column, it doesn't actually appear to be an age. This is because it's an actual Duration.
Duration
Duration is an exclusive type of data format in Power Query which represents the variations between the two DateTime values. Duration is a mix of four values:
days.hours.minutes.seconds
That's the way you see the numbers above. But from the standpoint of the user it is not their responsibility to understand the meaning of numbers like that. There are ways you can get every segment of the duration. using the Duration menu option you'll be able to take the number of seconds, minutes, hours, days , and years from it.
To aid in calculating the age in years with an example, it is easy to select Total Years:
The duration is calculated in days . It was then divided in 365 to provide the annual amount.
Rounding
The bottom line is that nobody declares your age as 53.813698630136983! They use 53 which is reduced to a lower number. You can select Rounding and Round Down in the Transform tab.
This will give you an indication of that you're old enough to be
You can then cleanse the other columns, if desired (or there could be because you made use of transformations on the Transform tab, to prevent creating new columns) You can also name this column; Age:
Things to Know
- Refresh The data's age that is calculated this way will be refreshed when you refresh your database. Each time, the system will be capable of comparing the birth date to the date and the date and time of refreshing. This method can be described as an algorithm to calculate the age. If you'd like the calculation of age to be performed dynamically with DAX here's how I have described the method I would recommend making use of.
- The reasoning behind Power Query: Benefits of using age calculation with Power Query is that the calculation is done when you refresh your report. This is done by using an application that makes calculations easy and quicker, and there's no extra cost to calculate it using DAX as a measure of runtime.
- Other scenarios They aren't meant to be used for calculation of age from birthdate. It can be used to calculate the age of inventory of items and also the differing dates and dates that differ from one 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 of Computer engineering. More than twenty years' experience working in the field of data analysis data, BI, databases development, and programming generally with Microsoft technologies. He was an Microsoft Data Platform MVP for nine years in a row (from 2011 to the present) because of his love of Microsoft BI. Reza is a prolific writer and co-founder at RADACAD. Reza is also the co-founder and organizer of the Difinity event 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 some books on MS SQL BI and also is writing some other books. He was also a regular member of technical forums online such as MSDN and Experts-Exchange and was a moderator on the MSDN SQL Server forums as well as an MCP and MCSE aswell as an MCITP in Business Intelligence. He also is the leader for the New Zealand Business Intelligence users group. This group is also the writer of the book that is loved by many. Power BI from Rookie to Rock Star, which is completely free and includes more than 1700 pages of material and a second book titled 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 Group for Users. And He is a Microsoft Certified Trainer.
Reza's dream is to help people find the best solutions for data. he's a Data enthusiast.This post was posted under Power BI, Power BI from Rookie to Rockstar, Power Query and is filed under Power BI, Power BI from Rookie to Rock Star, Power Query. This is a great resource for you to bookmark.
Post navigation
Share Different Visual Pages with different Security Groups. PowerBIAge in Years Calculation , which works for Leap Year in Power BI using Power Query
Comments
Post a Comment