Forum Discussion

dataaanana's avatar
dataaanana
Frequent Visitor
2 years ago

Need help in creating a histogram from a measure

Hello! I have an [Age] measure that calculates the age of active employees given a chosen year. I'm attempting to create a histogram to show the distribution of the ages of active employees given a chosen year using this measure. Is this possible? Below is the Age measure formula used: 

Age =
VAR _selyear =
    MAX(_Calendar[Year])
VAR _age =
    CALCULATE(
        DATEDIFF(SELECTEDVALUE(hr_coredata[DOB]),DATE(_selyear, 12, 31 ), YEAR ),
        ALL(_Calendar),_Calendar[Year]<=_selyear)
RETURN
_age


I tried creating the histogram using a calculated column but since it's a calculated column, ages will not be updated if I select other years.

I tried categorizing the ages of all active employees given a selected year using the formula below but I'm not really sure how I can used this in creating my histogram:

Age Category =
VAR _age = [Age]  // Assuming [Age] is the name of your existing Age measure

RETURN
SWITCH(
    TRUE(),
    _age < 25, "Under 25",
    _age >= 25 && _age <= 34, "25-34",
    _age >= 35 && _age <= 44, "35-44",
    _age >= 45 && _age <= 54, "45-54",
    _age >= 55, "55+"
)

Please help! Thank you so much.





1 Reply