Forum Discussion
Age gap difference
- Anonymous4 years ago
Hi Anonymous ,
Suppose we have a table like this:
Make a copy in the Power Query Editor, Replace values.
Select the [Club Name] column, and unpivot the other columns.
Add a new index column. close and apply.
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 _resultUsing the calculated columns as a conditional format for the fields of the matrix, the results are shown in the figure.
The PBIX file is attached for reference.
Best Regards,
Gao
Community Support TeamIf 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
- Anonymous4 years ago
Hi Anonymous ,
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 _resultBest Regards,
Gao
Community Support Team
Hi Anonymous ,
Suppose we have a table like this:
Make a copy in the Power Query Editor, Replace values.
Select the [Club Name] column, and unpivot the other columns.
Add a new index column. close and apply.
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.
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
- Anonymous4 years agoNot applicable
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?- Anonymous4 years agoNot applicable
Hi Anonymous ,
Copy a column and rename it to Index.
replace values and change data type to whole number.
The rest of the calculations remain the same.
The PBIX file is attached for reference.
Best Regards,
Gao
Community Support TeamIf 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
- Anonymous4 years agoNot applicable
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?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.Thanks in advance!