Age Calculation
Age Calculation in Power BI using Power Query
Power Query has a simple method of calculating the age. But, because DAX is the most popular language usedin several functionsin Power BI, many don't know the functions available in Power Query. In this article I will discuss how simple it is to calculateAge in Power BI in conjunction with PowerBI. This methodis extremely beneficial in cases where the calculation of the agecan be calculated on a row-by-row basis.
Calculate Age from a date
Here is the DimCustomer table, which is one of AdventureWorksDW table and is an aged column. I've eliminated a few additional columns in order to make the table simpler to navigate.
To calculate the age and gender of every consumer, all you have to do is to:
- In Power BI Desktop, Click on Transform Data
- On the Power Query Editor window; start by selecting the Birthdate column.
- Click on the Add Column Tab, which is under the "From Date & Time" section. Under Date select the age range.
That's about it. This can calculate an amount that is the sum of the Birthdate column as well as the current date as well as time.
However, the appearance of the age in the Age column, but it doesn't really appear like an age. It is due to the fact that it is the duration.
Duration
Duration is a specific kind of data structure that can be found inside Power Query which represents the distinction in two DateTime values. Duration is a combination of four numbers:
days.hours.minutes.seconds
You will discover in these values. But, from a person's viewpoint, they shouldn't have to find specifics similar to the ones mentioned above. There are ways to get every part of the time. Utilizing the Duration menu option, you'll be able to see the range of seconds to minutes, hours, and years out of it.
To calculating the age in years like, for instance you just need to go on to Total Years.
The duration is calculated in days , then divided by 365, giving you the annual value.
Rounding
Also, nobody claims that they're 53.813698630136983! They say 53, with a rounding down. You can choose the Rounding option and round down the Transform tab.
This will give you an indication of how old you are:
Then, you can purify other columns if desired (or you could have used transformations under the Transform tab to avoid creating new columns) It is possible to name this column as Age.
Things to Know
- Refresh The age that is calculated by the method will be updated each time you refresh your database. And each time, it compares your birthdate to the date and timing at the time of refresh. This method is a pre-calculation of an age. If, however, you want the age calculation to be performed dynamically, using DAX here is how I described a way that you can make use of.
- Why you should choose Power Query: Benefits of performing calculations on age in Power Query is that the calculation is made at the time of refreshing your report. This is accomplished using a tool that makes calculations easier, and there's no need for the extra cost of using DAX as a measure of the runtime.
- Another situation where this method is not utilized to calculate the birthdate as an age. This can be used to calculate inventory of products as and the difference between two dates and dates from one another.
Video
REZA RAD
TRAINER, CONSULTANT, MENTORReza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He holds a BSc in Computer engineering. He has more than 20 years of experience in data analysis database, BI, programmingand development primarily focused on Microsoft technologies. He has been a Microsoft Data Platform MVP for nine consecutive years (from 2011 to the present) due to his dedication for Microsoft BI. Reza is a prolific author and co-founder of RADACAD. Reza is also co-founder as well as organizer of 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 has written several books on MS SQL BI and also is working on other books. In addition, he was a frequent participant in online forums on technical matters like MSDN and Experts-Exchange as well as moderator of MSDN SQL Server forums, and is an MCP and an MCSE and MCITP for BI. As the group's director, he is in charge of New Zealand Business Intelligence users group. He is also the author of the highly acclaimed title Power BI from Rookie to Rock Star, which is available for download for free and includes more than 17000 pages of information and another book titled 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 User Groups. And He is a Microsoft Certified Trainer.
Reza's passion is to help you find the most efficient ways to use data, and he's an avid Data enthusiast.This article was published in Power BI, Power BI from Rookie to Rockstar, Power Query and closely related to Power BI, Power BI from Rookie to Rock Star, Power Query. This is a fantastic resource to save to your bookmarks.
Post navigation
- Share various visual pages using different security groups that PowerBIAge uses for Year Calculation that works for Leap Year in Power BI with Power Query
Comments
Post a Comment