=Aggr(
// We define the final columns, the first and the last
IF(Only({}Name) = 'Previous year',
dual(Only({}Name),-1000),
IF(Only({}Name) = 'Current year',
dual(Only({}}>}Name), 1000),
// We rank in descending order of the deviation module of product groups
IF(
Rank(
Fabs(
Sum({<
Attribute -= {'Totals','Coefficient'},
Date = {'>=$(=MakeDate(2017,1,1)))<=$(=MakeDate(2017,12,31))'}
>}[Qty])-
Sum({<
Attribute -= {'Totals','Coefficient'},
Date = {'>=$(=MakeDate(2016,1,1)))<=$(=MakeDate(2016,12,31))'}
>}[Qty])
)
,1
) <= $(vTop),
// Everything above the vTop parameter is displayed in the diagram
dual(
Only({}Name),
Rank(
Fabs(
Sum({<
Attribute -= {'Totals','Coefficient'},
Date = {'>=$(=MakeDate(2017,1,1)))<=$(=MakeDate(2017,12,31))'}
>}[Qty])-
Sum({<
Attribute -= {'Totals','Coefficient'},
Date = {'>=$(=MakeDate(2016,1,1)))<=$(=MakeDate(2016,12,31))'}
>}[Qty])
)
,1
)
),
// Everything below the vTop parameter is put into the 'Others' group
dual('Others',999)
)))
,Name)
If(WildMatch(Name,'Previous year','Current year','*'),
Pick(
WildMatch(Name,'Previous year','Current year','Coefficient','*'),
// for the previous year, we take the data of 2016
Sum({=$(=MakeDate(2016,1,1)))<=$(=MakeDate(2016,12,31))'}>}[Qty]),
// for the current year, here are the data of 2017
Sum({=$(=MakeDate(2017,1,1)))<=$(=MakeDate(2017,12,31))'}>}[Qty]),
// for product groups, we take the deviation
Sum({=$(=MakeDate(2017,1,1)))<=$(=MakeDate(2017,12,31))'}>}[Qty])-
Sum({=$(=MakeDate(2016,1,1)))<=$(=MakeDate(2016,12,31))'}>}[Qty])
),
// if the group is not included in the list of required, then we use this formula
// in our case, this is the 'Others' group
Sum({=$(=MakeDate(2017,1,1)))<=$(=MakeDate(2017,12,31))'}>}[Qty])-
Sum({=$(=MakeDate(2016,1,1)))<=$(=MakeDate(2016,12,31))'}>}[Qty])
)
If(Attribute = 'Totals', Blue(),
If(Expression < 0, Red(),Green()))
If(Attribute <> 'Totals',
rangesum(above( 'Expression', 1, rowno() )),
0
)
=Aggr(
// We define the final columns, the first and the last
IF(Only({}Name) = 'Previous year',
dual(Only({}Name),-1000),
IF(Only({}Name) = 'Current year',
dual(Only({}}>}Name), 1000),
// We rank in descending order of the deviation module of product groups
IF(
Rank(
Fabs(
Sum({<
Attribute -= {'Totals','Coefficient'},
Date = {'>=$(=MakeDate(2017,1,1)))<=$(=MakeDate(2017,12,31))'}
>}[Qty])-
Sum({<
Attribute -= {'Totals','Coefficient'},
Date = {'>=$(=MakeDate(2016,1,1)))<=$(=MakeDate(2016,12,31))'}
>}[Qty])
)
,1
) <= $(vTop),
// Everything above the vTop parameter is displayed in the diagram
dual(
Only({}Name),
Rank(
Fabs(
Sum({<
Attribute -= {'Totals','Coefficient'},
Date = {'>=$(=MakeDate(2017,1,1)))<=$(=MakeDate(2017,12,31))'}
>}[Qty])-
Sum({<
Attribute -= {'Totals','Coefficient'},
Date = {'>=$(=MakeDate(2016,1,1)))<=$(=MakeDate(2016,12,31))'}
>}[Qty])
)
,1
)
),
// Everything below the vTop parameter is put into the 'Others' group
dual('Others',999)
)))
,Name)
If(WildMatch(Name,'Previous year','Current year','*'),
Pick(
WildMatch(Name,'Previous year','Current year','Coefficient','*'),
// for the previous year, we take the data of 2016
Sum({=$(=MakeDate(2016,1,1)))<=$(=MakeDate(2016,12,31))'}>}[Qty]),
// for the current year, here are the data of 2017
Sum({=$(=MakeDate(2017,1,1)))<=$(=MakeDate(2017,12,31))'}>}[Qty]),
// for product groups, we take the deviation
Sum({=$(=MakeDate(2017,1,1)))<=$(=MakeDate(2017,12,31))'}>}[Qty])-
Sum({=$(=MakeDate(2016,1,1)))<=$(=MakeDate(2016,12,31))'}>}[Qty])
),
// if the group is not included in the list of required, then we use this formula
// in our case, this is the 'Others' group
Sum({=$(=MakeDate(2017,1,1)))<=$(=MakeDate(2017,12,31))'}>}[Qty])-
Sum({=$(=MakeDate(2016,1,1)))<=$(=MakeDate(2016,12,31))'}>}[Qty])
)
If(Attribute = 'Totals', Blue(),
If(Expression < 0, Red(),Green()))
If(Attribute <> 'Totals',
rangesum(above( 'Expression', 1, rowno() )),
0
)