The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have a age column which i want to create a measure with age group in different from 0 to 82.
Hi @asiat2 ,
Regarding age bucketing, it sounds like you’re currently using a pre-calculated column for age. However, since age changes every day, I recommend calculating it dynamically based on the birthdate rather than using a static, pre-calculated column. A calculated column will only be accurate for the specific day the report was generated. Instead, you can create age buckets based on the dynamic measure of age you calculate in real-time.
Best regards,
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.
This solution doesn't work for me:
Hi there, hoping you can help.
I tried the above but am getting the following error:
Argument '16' in SWITCH function is required.
please elaborate
User | Count |
---|---|
26 | |
12 | |
8 | |
8 | |
5 |
User | Count |
---|---|
28 | |
13 | |
12 | |
12 | |
6 |