Age Calculation
Age Calculation in Power BI using Power Query
Power Query has a simple method of calculating the age. However, as DAX is the most popular language usedin many computationsin Power BI, many do not know this function to Power Query. In this article, I'll go over how easy to calculateAge in Power BI by using PowerBI. It is a methodis extremely effective when your estimation of your agecan be calculated on a pre-calculated on a row basis.
Calculate Age from a date
Below you can view the DimCustomer table, which comprises the AdventureWorksDW table that has the birthdate column. I've removed several of the columns that aren't needed for ease of read;
In order to calculate the age of each buyer, you need is:
- In Power BI Desktop, Click on Transform Data
- In the Power Query Editor window; begin by selecting the column with the birthdate.
- click on the Add Column Tab, then click on"Add Column" and then on "From Date & Time" section. Under Date select the date range.
That's all there is. This will calculate an amount that is the total of the column for birthdate, Birthdate column, as well as the time and date column.
However, the age that appears in the Age column, it doesn't actually seem to be an actual age. This is because it's an actual duration.
Duration
Duration is a special kind of data format in Power Query which represents the differences of the two DateTime values. Duration is a mix of four different values:
days.hours.minutes.seconds
and that's how you take the above numbers. But from the viewpoint of the user, it's not their responsibility to know the specifics of that. there are ways that you are able to obtain every segment of the duration. When you select the Duration menu it will be apparent that you can get the duration in seconds or minutes, hours, months and days from it.
For help calculating the age in years by way of example it is simple to select Total Years:
The duration was calculated in days . It was then divided in 365days to give you the annual value.
Rounding
At the final point, no one declares your age in 53.813698630136983! They call it 53, which is reduced to a lower number. It is possible to select Rounding and Round Down in the Transform tab for it.
This will let you know what your age is in terms of years
You can then clean the other columns, should you like (or there could be that you have used transformations on the Transform tab to avoid creating new columns.) You can also name this column: Age
Things to Know
- Refresh The information's age calculated using this method will be refreshed each time you refresh your database. Each time it is refreshed, the system will be capable of comparing the birth date with the date as well as the time in the process of refreshing. It is a method will be an algorithm that is used to pre-calculate the age. If you'd like the age calculation to be executed dynamically by using DAX here is how I explained the best way to make use of.
- The reason behind Power Query: Benefits from using age calculation in Power Query is that the calculation takes place when you refresh your report. This is achieved by using an application that makes calculations significantly faster and easier, and there's no extra cost for calculating it using DAX as a measure of runtime.
- Other scenarios These are not intended for the calculation of age from birth date. It is possible to calculate the age of inventory in the case of products and also the various dates and dates from one other.
Video
REZA RAD
TRAINER, CONSULTANT, MENTORReza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has a BSc with a concentration in Computer engineering. More than twenty years' expertise in the area of data analysis as well as databases, BI developing, and programming mostly using Microsoft technologies. He has been a Microsoft Data Platform MVP for nine consecutive years (from 2011 until the present) because of his love of Microsoft BI. Reza has been a prolific writer and co-founder of RADACAD. Reza is also the co-founder and organizer of the Difinity event 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 has written books on MS SQL BI and also is working on different books. He was also a regular participant in online forums for technical issues like MSDN and Experts-Exchange and was moderator of MSDN SQL Server forums, and is an MCP and MCSE , as well with an MCITP in BI. He is also the head for the New Zealand Business Intelligence users group. The group is also the creator of the book extremely well-loved Power BI from Rookie to Rock Star, which is totally free and comes with greater than 1700 page and a book that is 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 user group. And He is a Microsoft Certified Trainer.
Reza's desire is to help users find the right solutions to manage data. He's an avid Data enthusiast.This post was posted with Power BI, Power BI from Rookie to Rockstar, Power Query and is classified under Power BI, Power BI from Rookie to Rock Star, Power Query. This is a fantastic resource to save to your bookmarks.
Post navigation
Share Different Visual Pages with different Security Groups. PowerBIAge in years calculation that is used for Leap Year in Power BI by using Power Query
Comments
Post a Comment