Age Calculation
Age Calculation in Power BI using Power Query
Power Query has a simple way in calculating the age. However, as DAX is the most popular language usedin several calculationsin the Power BI platform, many do not know about the function that is available in Power Query. In this blog , I will describe how simple to calculateAge in Power BI with Power BI. The methodis extremely useful for situations in which the computation of an agecan be conducted on a previous calculated row by row basis.
Calculate Age from a date
That's the DimCustomer table that is part of the AdventureWorksDW table that has the birthdate column. I've removed some columns that aren't necessary in order to make it easier to read;
For you to calculate the exact age each buyer, you need is:
- In Power BI Desktop, Click on Transform Data
- In the Power Query Editor window; choose the first column, Birthdate.
- Click on the Add Column Tab. Under "From Date & Time" section, and then under Date Choose the age range.
That's all there is to it. this calculates the calculate an amount that is the sum of the Birthdate column, along with the current date and the time.
But, the age that is displayed in the Age column, doesn't seem to be an actual age. That is because it is an actual duration.
Duration
Duration is a distinct form of data used by Power Query which represents the differences between the two DateTime values. Duration is the result of four numbers:
days.hours.minutes.seconds
This is the way you interpret the above statements. But, from someone else's viewpoint, you wouldn't want them to find data like this. There are methods that can extract each segment that's what you need to know about time. When you select the Duration menu you'll discover that you can extract the amount of seconds or minutes or hours, days, and years from it.
to assist with calculating the age in years like, for instance it is simple to choose Total Years.
Note that the length for the course is calculated in days , then subdivided into 365 so that you can come up with the annual cost.
Rounding
Finally, no one says they are 53.813698630136983! They use the term 53, and then then round it down. It's easy to select rounding as well as Round Down in the Transform tab.
This will give you the number in years:
It's also possible to cleanse other columns if you'd like (or perhaps you've taken advantage of transformations using the Transform tab to stop the creating of additional columns) The column could be renamed to Age column and Age:
Things to Know
- Refresh The age that is calculated by this method will be updated every time you refresh your database. Every time, the database will be compared the birthdate to the date and the date at which the refreshed. This method is an earlier calculation of the age. If you're looking for this calculation run dynamically using DAX, here I provided a method you could use.
- The rationale for Power Query: Benefits of performing age calculations in Power Query is that the calculation is carried out while you refresh the report. The report is refreshed using a tool that makes the calculation more efficient, and there's no cost of doing it with DAX to gauge the runtime.
- Another case where these are not in use to calculate age, only beginning from the birth date. It could be used to calculate the age of inventory for items and also to determine the differences between two dates or dates from each other.
Video
REZA RAD
TRAINER, CONSULTANT, MENTORReza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has a BSc of Computer engineering. He holds the more than 20 years' knowledge in the field of data analysis and BI, database development and programming, mostly based on Microsoft technologies. He has been a Microsoft Data Platform MVP for 9 consecutive years (from 2011, until now) for his commitment toward Microsoft BI. Reza has been an active writer and co-founder of RADACAD. Reza is co-founder and co-organizer for the Difinity Conference which is held 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 written a couple of book about MS SQL BI and also is working on more books. He was also a frequent participant on technical forums online such as MicrosoftDN as well as Experts-Exchange and was the moderator for MSDN SQL Server forums, and holds the MCP as well as MCSE and MCITP for Business Intelligence. He is the founder of the New Zealand Business Intelligence users group. Also, the creator of the famous publication Power BI from Rookie to Rock Star, which is free with more than 170 pages of content as well as it is a portion of 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 Groups. And He is a Microsoft Certified Trainer.
Reza's passion is to help users discover the most efficient solutions for their data, and he's a Data enthusiast.This article was published within Power BI, Power BI from Rookie to Rockstar, Power Query and is listed into Power BI, Power BI from Rookie to Rock Star, Power Query. You can follow any comments to this entry through the RSS feed.
Post navigation
Create different visual pages and share them with different security groups in Power BIAge in Years Calculation that can be used as a way to calculate Leap Year in Power Business Intelligence by using Power Query
Comments
Post a Comment