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 well-known language usedin several functionsin Power BI, a lot of users don't realize the function available in Power Query. In this article I will explain how easy it is to calculateAge within Power BI with Power BI. This methodis very beneficial in situations where the calculation of the agecan be completed on a pre-calculated row-by-row basis.
Calculate Age from a date
Here is the DimCustomer table that's one of AdventureWorksDW table, which is one of the columns that is a time column. I've removed a few additional columns, to make it easier to comprehend.
In order to calculate the age of every buyer, all you have to do is:
- In Power BI Desktop, Click on Transform Data
- Inside the Power Query Editor window; begin by choosing the column titled Birthdate.
- Click on the Add Column Tab that is located in the "From Date & Time" section. Also, under Date choose the appropriate age range.
That's all there is to it. It can calculate an amount that is equal to the sum of the column for birthdate, Birthdate column as well as the present date, as well as the time.
However, the age that appears in this Age column, but it doesn't really look like an age. It is due to the fact that it is the duration.
Duration
Duration is a special kind of data format used within Power Query which represents the distinction in two DateTime values. Duration is a mixture with four values:
days.hours.minutes.seconds
It's exactly what you'll observe in the following values. From a personal viewpoint, they shouldn't have to seek out specifics such as the ones above. There are methods to capture every second of the time. When you select the menu option Duration, you'll notice the amount of seconds to minutes, hours, days, and years.
For calculating the age in years like, for instance it's as easy as going to Total Years.
The duration is calculated in days , then divided by 365. This gives you the value for the year.
Rounding
No one has claimed they are 53.813698630136983! they claim 53, and then round it down. You can select the rounding option, and then round down the Transform tab.
This will show you that you're old enough to be
It is then possible to purify other columns if desired (or you could have used transformations in the Transform tab to avoid making new columns.) You could name this column as Age.
Things to Know
- Refresh: The age calculated by this method is updated each time you are refreshing your dataset. Each time, it will compare your birthdate with the date and moment of the refresh. This method is pre-calculating an age. If, however, you require the calculation of an age to be done dynamically with DAX, this is how I have described a technique you could use.
- Reasons to choose Power Query: Benefits of performing age calculations in Power Query is that the calculation takes place during the process of refreshing your report. This is performed by making use of a tool that makes calculations much easier and there's no need for the added cost of calculating it with DAX as a measure of running time.
- Another possibility is that it cannot be utilized to calculate the age based on birth date. It could be used to determine inventory of goods as and the difference between two dates and times one another.
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. The engineer has over 20 years' experience in data analysis , database, BI, programmingand development with a focus in Microsoft technologies. He is an official Microsoft Data Platform MVP for nine consecutive years (from 2011 until today) because of his commitment towards Microsoft BI. Reza is known as an prolific author and co-founder of RADACAD. Reza is also the co-founder and co-organizer of the 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 wrote a couple of books about MS SQL BI and also is writing some others, In addition, he was a frequent participant in online forums on technical issues , such as MSDN and Experts-Exchange . He also serves as moderator for MSDN SQL Server forums, and is an MCP , MCSE as well as an MCITP for Business Intelligence. As the group's director, he is in charge of New Zealand Business Intelligence users group. Also, he's author of the incredibly popular books such as Power BI from Rookie to Rock Star, which is freely available and contains more than 17000 pages of information . It also includes an additional 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, as well as SQL User Groups. And He is a Microsoft Certified Trainer.
Reza's goal is to help you discover the most effective methods to manage data, and he's an avid Data enthusiast.This post was originally published by Power BI, Power BI from Rookie to Rockstar, Power Query and related to Power BI, Power BI from Rookie to Rock Star, Power Query. This article is an excellent source to bookmark.
Post navigation
- Share different visual pages by using Different Security Groups that PowerBIAge uses for Year Calculation that works for Leap Year in Power BI using Power Query
Comments
Post a Comment