I'm new in SSRS reports. I have a problem, it drives me crazy for several days.
There is a set of categories and subcategories, like this:
A - categoryA
A - categoryA.A01 - subcat A01
A - categoryA.A01 - subcat A01.A01A - subcat A01A
A - categoryA.A02 - subcat A02
B - categoryB
C - categoryC
D - categoryD
...
I created a report, where each row represents category or subcategory. I need to set unique background color for each row. I've already tried so many combinations of SWITCH and IIF statements, and none of them works like I need.
Considering that category name can change, and each subcategory in its name contains the name of all parent categories separated by a dot, I use Split() and Left() functions to get the code at the beginning of the category or subcategory name, only this
code will not change.
This expression works better than others, but not quite as it should. It sets the same color for subcategories of the same level.
=Switch(Left(Fields!Category.Value,1) = "A",
IIF(Split(Fields!Category.Value, ".").length = 1,
"#e4daf3",
IIF(Split(Fields!Category.Value, ".").length = 2,
"#8db4e2",
IIF(Split(Fields!Category.Value, ".").length = 3,
"#ebf1de","#00ff00"))),
Left(Fields!Category.Value,1) = "B", "#fdd9d9",
Left(Fields!Category.Value,1) = "C", "#fcffd4",
Left(Fields!Category.Value,1) = "D", "#8de2de",
Left(Fields!Category.Value,1) = "E", "#c6e6fd"
)
I've tried to make this expression better, in so many ways, like this:
=Switch(Left(Fields!Category.Value,1) = "A",
IIF(Split(Fields!Category.Value, ".").length = 1,
"#e4daf3",
IIF(Split(Fields!Category.Value, ".").length = 2 AND Left(Split(Fields!Category.Value, ".")(1),3) = "A01",
"#8db4e2",
IIF(Split(Fields!Category.Value, ".").length = 2 AND Left(Split(Fields!Category.Value, ".")(1),3) = "A02",
"#ff0000",
IIF(Split(Fields!Category.Value, ".").length = 3 AND Left(Split(Fields!Category.Value, ".")(2),4) = "A01A",
"#0000ff","#00ff00")))),
Left(Fields!Category.Value,1) = "B", "#fdd9d9",
Left(Fields!Category.Value,1) = "C", "#fcffd4",
Left(Fields!Category.Value,1) = "D", "#8de2de",
Left(Fields!Category.Value,1) = "E", "#c6e6fd"
)
But this expression somehow set background color only to subcategories, root categories are clear, no background at all.
Maybe I didn't see something, or maybe there is some rules that forbid using nested SWITCHes and IIFs. Help me, please.