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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Power BI Dynamic Calculation based on dynamic filter and date selection

Hi All,

I have the following scenario-

1) Age category (Adult, Child and You Adult)- It is coming from a table. The column is being used as a slicer:

   

mukherjees_0-1654611196398.png

Adult - age 26 and above (>26)

Young Adult - age 18 to 26 (>=18 and <=26)

Child - age less than 18 (<18)

2) I have a table with unique ID's and date of birth:

 

mukherjees_1-1654611308805.png

 

3) A third table (as a date dimension), which gives me sample dates that the user can select:

mukherjees_2-1654611364995.png

 

Requirement -

1) The user will select a date from the Day slicer and a category from  the category slicer.

2) Based on the day selection, the age calculation has to be dynamic and based on the category, the count of rows from the second table are to be returned.

 

For example - I select 06/06/2022 - based on this date, the age of the rows of the second table will be calculated, and I select category "Young Adult". Hence, the count will only be of rows which have age from 18 to 26.

 

I have tried to make it work but unsuccessfully. I would appreciate if someone could guide me to a solution if at all this is possible to do in PBI. Thank you.

 

Link to my PBI file - https://github.com/sommkh/pbi_age_test/blob/2cc9eb7dbe7788ea21da5ba1bb8c7f08adca60e2/Age_Test_Datase...

 

 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could create the measure as follow:

DIFF = CALCULATE (
        ROUNDDOWN (
            DATEDIFF ( MIN ( AGE_TEST_DATA[IND_BIRTH_DT] ), MAX('D_DATE'[DATE]), MONTH ) / 12,
            0))
count = 
SWITCH(MAX('AGE_CATEGORY'[CATEGORY]),"Adult",CALCULATE(COUNT('AGE_TEST_DATA'[ID]),FILTER('AGE_TEST_DATA',[DIFF]>26)),
"Young Adult",CALCULATE(COUNT('AGE_TEST_DATA'[ID]),FILTER('AGE_TEST_DATA',[DIFF]>=18&&[DIFF]<=26)),
"Child",CALCULATE(COUNT('AGE_TEST_DATA'[ID]),FILTER('AGE_TEST_DATA',[DIFF]>=0&&[DIFF]<18)))

The final show:

vyalanwumsft_0-1654843935733.pngvyalanwumsft_1-1654843946796.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could create the measure as follow:

DIFF = CALCULATE (
        ROUNDDOWN (
            DATEDIFF ( MIN ( AGE_TEST_DATA[IND_BIRTH_DT] ), MAX('D_DATE'[DATE]), MONTH ) / 12,
            0))
count = 
SWITCH(MAX('AGE_CATEGORY'[CATEGORY]),"Adult",CALCULATE(COUNT('AGE_TEST_DATA'[ID]),FILTER('AGE_TEST_DATA',[DIFF]>26)),
"Young Adult",CALCULATE(COUNT('AGE_TEST_DATA'[ID]),FILTER('AGE_TEST_DATA',[DIFF]>=18&&[DIFF]<=26)),
"Child",CALCULATE(COUNT('AGE_TEST_DATA'[ID]),FILTER('AGE_TEST_DATA',[DIFF]>=0&&[DIFF]<18)))

The final show:

vyalanwumsft_0-1654843935733.pngvyalanwumsft_1-1654843946796.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.