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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
abhishek_2593
Helper II
Helper II

Age gap difference

Hi,

 

i have a dataset of various clubs having teams of different age groups.

i want to calculate if there is more than 2 years age gap between teams under each club.
how can i calculate the age gap?

 

The dataset is similar to this where U9-U16 are the teams of age groups under9 to under 16.

abhishek_2593_0-1657174924261.png

The condition is there should not be more than 2 years age gap between teams so i need to calculate this.

For Ex: CLub 1 - There is a team in U12 and Team in U16 and the age difference between these two team is 4 which does not satisy my criteria. How do i calculate this in PowerBI?

2. How can i calculate/highlight the clubs which are satisfying the 2 year age gap criteria?

Please help. Thank you!

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @abhishek_2593 ,

 

Suppose we have a table like this:

vcgaomsft_1-1657519500623.png

Make a copy in the Power Query Editor, Replace values.

vcgaomsft_3-1657519866754.png

vcgaomsft_4-1657519947086.png

Select the [Club Name] column, and unpivot the other columns.

vcgaomsft_0-1657519426967.png

Add a new index column. close and apply.

vcgaomsft_5-1657520019770.png

Please new a calculated column:

Column = 
VAR _club = IF( 'Table2'[Value] = 1 , 'Table2'[Club Name])
VAR _index = IF( 'Table2'[Value] = 1 , 'Table2'[Index])
VAR _index1 = _index - 2
VAR _index2 = _index - 1
VAR _index3 = _index + 1
VAR _index4 = _index + 2
VAR _result1 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index1&&'Table2'[Club Name]=_club))
VAR _result2 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index2&&'Table2'[Club Name]=_club))
VAR _result3 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index3&&'Table2'[Club Name]=_club))
VAR _result4 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index4&&'Table2'[Club Name]=_club))
VAR _result = 
SWITCH(
    TRUE(),
    _result1 = 1 , "GREEN",
    _result2 = 1 , "GREEN",
    _result3 = 1 , "GREEN",
    _result4 = 1 , "GREEN",
    "RED"
)
RETURN
_result

Using the calculated columns as a conditional format for the fields of the matrix, the results are shown in the figure.

vcgaomsft_6-1657522593042.png

The PBIX file is attached for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

Anonymous
Not applicable

Hi @abhishek_2593 ,

 

Please try this:

Column = 
VAR _club = IF( 'Table2'[Value] <> 0 , 'Table2'[Club Name])
VAR _index = IF( 'Table2'[Value] <> 0 , 'Table2'[Index])
VAR _index1 = _index - 2
VAR _index2 = _index - 1
VAR _index3 = _index + 1
VAR _index4 = _index + 2
VAR _result1 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index1&&'Table2'[Club Name]=_club))
VAR _result2 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index2&&'Table2'[Club Name]=_club))
VAR _result3 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index3&&'Table2'[Club Name]=_club))
VAR _result4 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index4&&'Table2'[Club Name]=_club))
VAR _result = 
SWITCH(
    TRUE(),
    _result1 <> 0 , "GREEN",
    _result2 <> 0 , "GREEN",
    _result3 <> 0 , "GREEN",
    _result4 <> 0 , "GREEN",
    "RED"
)
RETURN
_result

vcgaomsft_0-1657698041062.png

 

Best Regards,
Gao

Community Support Team

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @abhishek_2593 ,

 

Suppose we have a table like this:

vcgaomsft_1-1657519500623.png

Make a copy in the Power Query Editor, Replace values.

vcgaomsft_3-1657519866754.png

vcgaomsft_4-1657519947086.png

Select the [Club Name] column, and unpivot the other columns.

vcgaomsft_0-1657519426967.png

Add a new index column. close and apply.

vcgaomsft_5-1657520019770.png

Please new a calculated column:

Column = 
VAR _club = IF( 'Table2'[Value] = 1 , 'Table2'[Club Name])
VAR _index = IF( 'Table2'[Value] = 1 , 'Table2'[Index])
VAR _index1 = _index - 2
VAR _index2 = _index - 1
VAR _index3 = _index + 1
VAR _index4 = _index + 2
VAR _result1 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index1&&'Table2'[Club Name]=_club))
VAR _result2 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index2&&'Table2'[Club Name]=_club))
VAR _result3 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index3&&'Table2'[Club Name]=_club))
VAR _result4 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index4&&'Table2'[Club Name]=_club))
VAR _result = 
SWITCH(
    TRUE(),
    _result1 = 1 , "GREEN",
    _result2 = 1 , "GREEN",
    _result3 = 1 , "GREEN",
    _result4 = 1 , "GREEN",
    "RED"
)
RETURN
_result

Using the calculated columns as a conditional format for the fields of the matrix, the results are shown in the figure.

vcgaomsft_6-1657522593042.png

The PBIX file is attached for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Hi Gao,

Thank you! my dataset is something like this.
Only the teams available under a club is in the table.

In this situation, can i use the same steps you suggested?

abhishek_2593_0-1657533716847.png

 

Anonymous
Not applicable

Hi @abhishek_2593 ,

 

Copy a column and rename it to Index.

vcgaomsft_0-1657535641652.png

replace values and change data type to whole number.

vcgaomsft_1-1657535826606.png

vcgaomsft_2-1657535870910.png

The rest of the calculations remain the same.

The PBIX file is attached for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

 

Hi Gao,

Thank you very much, this is helpful!
But there is small issue where the age gap is shown as red even when there is more teams in the clubs.

For example this is screenshot of my data after applying your measures. Basically clubs with more teams in all age group but still showing red!(some clubs have more than 1 team in same age-group)
How do we deal with this? should we incldude more measures in the column?
abhishek_2593_0-1657695154736.png

abhishek_2593_1-1657696230717.png

 

 

Screenhsot of columns i created using your solution,
values are all =1
Index is replacement of ages and converted to whole number 
Column is your measure.

abhishek_2593_0-1657695392075.png

 

Thanks in advance!

Anonymous
Not applicable

Hi @abhishek_2593 ,

 

Would you please share some sample data that does not contain sensitive data? This will help me to find out the reason faster. Thanks in advance.

 

How to provide sample data in the Power BI Forum

 

Best Regards,
Gao

Community Support Team

Hi @Anonymous ,

 

Please let me know if you need more data apart from the above screenshots?

 

Thank you!

Anonymous
Not applicable

Hi @abhishek_2593 ,

 

Please try this:

Column = 
VAR _club = IF( 'Table2'[Value] <> 0 , 'Table2'[Club Name])
VAR _index = IF( 'Table2'[Value] <> 0 , 'Table2'[Index])
VAR _index1 = _index - 2
VAR _index2 = _index - 1
VAR _index3 = _index + 1
VAR _index4 = _index + 2
VAR _result1 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index1&&'Table2'[Club Name]=_club))
VAR _result2 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index2&&'Table2'[Club Name]=_club))
VAR _result3 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index3&&'Table2'[Club Name]=_club))
VAR _result4 = CALCULATE(SUM('Table2'[Value]),FILTER('Table2','Table2'[Index]=_index4&&'Table2'[Club Name]=_club))
VAR _result = 
SWITCH(
    TRUE(),
    _result1 <> 0 , "GREEN",
    _result2 <> 0 , "GREEN",
    _result3 <> 0 , "GREEN",
    _result4 <> 0 , "GREEN",
    "RED"
)
RETURN
_result

vcgaomsft_0-1657698041062.png

 

Best Regards,
Gao

Community Support Team

Hi @Anonymous ,

 

This works perfectly fine, Thanks a lot for your help 🙂 really appreciate it!
I hope to perfect these skills like you sometime soon!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.