Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
apmulhearn
Helper III
Helper III

Measure to Calculate Age Range Based on Group

Hello,

 

I have a table of guests travelling on various trips. Each trip has a unique code. A small sample is depicted below.

 

On Departure Code DGCRD:20221004LEO, there are 4 guests travelling, ages 68 - 77. I want to be able to calculate the range of ages - in this example, 9 years.

 

Additionally, I do not want to include blank/null values,

so DGCHRT:20221221LEO would be 53, as there are several guests with undisclosed ages.

 

Sample table:


Departure Code (Departure) (Departure)Depart AgeFirst Payment Date (Booking) (Booking)

DGCGRD:20220906LEO  
DGCGRD:20220906LEO  
DGCGRD:20221004LEO728/26/2020
DGCGRD:20221004LEO778/26/2020
DGCGRD:20221004LEO778/27/2020
DGCGRD:20221004LEO688/27/2020
DGCGEA:20231029LEO  
DGCBIN:20220122LEO7212/22/2021
DGCGRD:20220906LEO  
DGCBIN:20220122LEO7412/22/2021
DGCBEA:20221221-1LEO561/16/2020
DGCBEA:20221221-1LEO291/16/2020
DGCBEA:20221221-1LEO281/16/2020
DGCBEA:20221221-1LEO281/16/2020
DGCBEA:20221221-1LEO241/16/2020
DGCBEA:20221221-1LEO251/16/2020
DGCBEA:20221221-1LEO571/16/2020
DGCPHM:20220804LEO514/16/2021
DGCHRT:20221221LEO7312/22/2021
DGCHRT:20221221LEO2012/22/2021
DGCHRT:20221221LEO 12/22/2021
DGCHRT:20221221LEO 12/22/2021
DGCHRT:20221221LEO 12/22/2021
DGCTZS:20220807LEO1612/10/2019
DGCTZS:20220807LEO1612/10/2019
DGCTZS:20220807LEO4612/10/2019
DGCTZS:20220807LEO4712/10/2019
DGCPHM:20221222LEO3612/23/2021
DGCPHM:20221222LEO3812/23/2021
DGCPHM:20230803LEO504/16/2021
DGCPHM:20230803LEO524/16/2021
DGCPHM:20230803LEO154/16/2021
DGCPHM:20230803LEO174/16/2021
1 ACCEPTED SOLUTION

@apmulhearn  try this

Measure =
VAR _filt =
    FILTER (
        'Table',
        CALCULATE (
            COUNT ( 'Table'[Departure Code] ),
            ALLEXCEPT ( 'Table', 'Table'[Departure Code] )
        ) > 18
    )
VAR _partition =
    ALLEXCEPT ( 'Table', 'Table'[Departure Code] )
RETURN
    CALCULATE ( MAX ( 'Table'[Age] ), _partition, _filt )
        - CALCULATE ( MIN ( 'Table'[Age] ), _partition, _filt )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

5 REPLIES 5
smpa01
Super User
Super User

@apmulhearn  use this as a measure

Measure = CALCULATE(MAX('Table'[Age]),ALLEXCEPT('Table','Table'[Departure Code]))-CALCULATE(MIN('Table'[Age]),ALLEXCEPT('Table','Table'[Departure Code]))

 

smpa01_0-1641314707278.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi - thank you. This calculation is working well, but I don't think I explained my use case. I want to be able to compare the number of bookings where the range is greater than or equal to a certain number (say, 18) to the number of bookings as a whole. Can you help me here? 

@apmulhearn  try this

Measure =
VAR _filt =
    FILTER (
        'Table',
        CALCULATE (
            COUNT ( 'Table'[Departure Code] ),
            ALLEXCEPT ( 'Table', 'Table'[Departure Code] )
        ) > 18
    )
VAR _partition =
    ALLEXCEPT ( 'Table', 'Table'[Departure Code] )
RETURN
    CALCULATE ( MAX ( 'Table'[Age] ), _partition, _filt )
        - CALCULATE ( MIN ( 'Table'[Age] ), _partition, _filt )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@apmulhearn  did you try this out yet?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hello and sorry for the delay, I've been trying to use what you gave me and solve my problem, but I'm failing. When I use the measure in a chart, the below is what I receive. The first value is from the first Measure you suggested; the second value is from the second measure you suggested. 

I'm sure I'm messing this up but I'm not sure how.  What I want is to show, by year in the chart, a) how many bookings (identifiable by field 'Departure Code')  have an age range of 18 or more years, b) how many total bookings there are, and c) a as a percent of b.

apmulhearn_0-1642576905688.png

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors