Forum Discussion
Age group
In Power BI, you can create a measure that groups ages into different age groups using DAX (Data Analysis Expressions). Here's how you can do it:
Open your Power BI Desktop file and go to the "Model" view.
In the "Fields" pane, right-click on the table that contains the age column and select "New Measure."
Enter a name for your new measure, such as "Age Group."
Use the following DAX formula to create the age groups:
Age Group =
VAR Age = 'YourTableName'[Age] // Replace 'YourTableName' with the actual name of your table
RETURN
SWITCH(TRUE(),
Age >= 0 && Age <= 18, "0-18",
Age > 18 && Age <= 30, "19-30",
Age > 30 && Age <= 50, "31-50",
Age > 50 && Age <= 65, "51-65",
Age > 65 && Age <= 82, "66-82",
"Unknown"
)
Replace 'YourTableName' with the actual name of your table containing the age column.
This DAX formula creates a new measure called "Age Group" that categorizes ages into different age groups: "0-18," "19-30," "31-50," "51-65," "66-82," and "Unknown" for any age that doesn't fall into these ranges.
Click the checkmark to create the measure.
Now, you can use the "Age Group" measure in your visuals to group and display data by age groups. You can use it in tables, charts, and other Power BI visualizations to analyze your data based on these age groups.
Remember to adjust the age group ranges to match your specific needs if necessary.
Once you've created the measure, you can drag it into your visualizations to analyze your data by age group.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.
Hi there, hoping you can help.
I tried the above but am getting the following error:
Argument '16' in SWITCH function is required.