Hi SAP community!
I’d like to present a solution for conditionally styling the totals and subtotals in a table based on styling rules rather than hardcoded approach.
Problem Statement:
Consider this scenario where the customer wants to see the totals and subtotals highlighted in a separate color. In a static scenario where the rows don’t change, we can apply the colors manually by cell styling. However, in most cases the rows in the table always change based on the members. So, in order to tackle a changing table dynamically, we need to opt for styling rules. Not only is styling rules dynamic, but it also has better performance than manual cell styling.
Solution:
In order to handle the requirement, I have created a few styles and styling rules for the totals and subtotals of the table.
Based on the above screenshot, we can see that the totals, subtotal each have their own row color.
In order to achieve this,
Create a story in SAC and insert a table
I am using the sample model provided by SAP BestRunJuice_SampleModel for this blog. You can follow the exact same steps to replicate it.
Add the dimensions Product, Location and Sales managers in the row and Date dimension in the columns.
Enable Totals for each of the row dimensions.
Create 3 separate styles for each of the totals.
Firstly, let’s create a style for the totals with a green color fill and black bold text.
Secondly, Create a style for the second totals. I’m using a yellow fill to distinguish the overall totals with the subtotals.
And we shall create one more style for the lowest level subtotal with an orange fill and white text.
Create one more style for the data members with a dark black text.
Then create styling rules for each of the 3 totals and the data members.
For the overall totals, create a styling rule using the Totals style which we had initially created.
Then enable the ‘Hand’ based selection tool and choose the following checkboxes as depicted below.
Enabling the above checkboxes will affect the styling only to the data and header of the selected dimensions.
Click on the measure value ‘235.04’ as shown in the below screenshot by the highlighted box, which is on the same row as the overall totals. By doing so, the content analyzer will automatically detect the zone at which the styling needs to be applied.
On selecting ok button, the Totals styling will be applied in the table.
For the next subtotals, Click on the measure value ‘34.03’ as shown in the below screenshot. On doing so, the content analyzer will carefully detect the zones at which this needs to be applied.
One additional thing we need to do is to select the level as ‘Self & Sibling’ for Product and Sales manager.
This property will make the styling repeat for every other instance where the subtotal occurs.
The styling rules at the top will overrule the one listed below. It behaves the same way as a stack or an array would.
In this case, since the subtotals rule is above the totals rule, the green rule is getting overruled by the yellow rule.
Rearrange the styling rules based on the order of precedence.
Once we have Totals > Subtotals we will get our favorable output.
Now, we need to repeat the same for the next level of subtotals which is the Sales Manager level subtotal.
Select the checkboxes and Levels as mentioned in the screenshot below.
Similarly, the Styling rule sequence needs to be rearranged.
Once we have Totals > Subtotals > lowest level we will get our favorable output.
Finally, we can also set a styling rule for the data members.
For this, select the entire data range as shown in the screenshot below. Also choose the checkboxes and Levels appropriately.
Again, we need to rearrange the sequence.
Once we have Totals > Subtotals > lowest level> Members we will get our favorable output.
If we preview the final look in the Fullscreen, we can observe that the styling rules are repeating for every dimension member combination.
This method will improve the performance by eliminating manual cell styling.
Always go for styling rules wherever possible.
Hope this blog was helpful, if you have any doubts, you can always drop a comment below.
With regards,
Siva prakash.
Hi SAP community!I’d like to present a solution for conditionally styling the totals and subtotals in a table based on styling rules rather than hardcoded approach.Problem Statement: Consider this scenario where the customer wants to see the totals and subtotals highlighted in a separate color. In a static scenario where the rows don’t change, we can apply the colors manually by cell styling. However, in most cases the rows in the table always change based on the members. So, in order to tackle a changing table dynamically, we need to opt for styling rules. Not only is styling rules dynamic, but it also has better performance than manual cell styling.Solution:In order to handle the requirement, I have created a few styles and styling rules for the totals and subtotals of the table.Based on the above screenshot, we can see that the totals, subtotal each have their own row color.In order to achieve this, Create a story in SAC and insert a tableI am using the sample model provided by SAP BestRunJuice_SampleModel for this blog. You can follow the exact same steps to replicate it.Add the dimensions Product, Location and Sales managers in the row and Date dimension in the columns.Enable Totals for each of the row dimensions.Create 3 separate styles for each of the totals.Firstly, let’s create a style for the totals with a green color fill and black bold text.Secondly, Create a style for the second totals. I’m using a yellow fill to distinguish the overall totals with the subtotals.And we shall create one more style for the lowest level subtotal with an orange fill and white text.Create one more style for the data members with a dark black text.Then create styling rules for each of the 3 totals and the data members. For the overall totals, create a styling rule using the Totals style which we had initially created.Then enable the ‘Hand’ based selection tool and choose the following checkboxes as depicted below. Enabling the above checkboxes will affect the styling only to the data and header of the selected dimensions.Click on the measure value ‘235.04’ as shown in the below screenshot by the highlighted box, which is on the same row as the overall totals. By doing so, the content analyzer will automatically detect the zone at which the styling needs to be applied.On selecting ok button, the Totals styling will be applied in the table.For the next subtotals, Click on the measure value ‘34.03’ as shown in the below screenshot. On doing so, the content analyzer will carefully detect the zones at which this needs to be applied.One additional thing we need to do is to select the level as ‘Self & Sibling’ for Product and Sales manager.This property will make the styling repeat for every other instance where the subtotal occurs.The styling rules at the top will overrule the one listed below. It behaves the same way as a stack or an array would.In this case, since the subtotals rule is above the totals rule, the green rule is getting overruled by the yellow rule.Overlapping of styling rule Rearrange the styling rules based on the order of precedence.Once we have Totals > Subtotals we will get our favorable output.Now, we need to repeat the same for the next level of subtotals which is the Sales Manager level subtotal.Select the checkboxes and Levels as mentioned in the screenshot below.Similarly, the Styling rule sequence needs to be rearranged.Once we have Totals > Subtotals > lowest level we will get our favorable output.Finally, we can also set a styling rule for the data members.For this, select the entire data range as shown in the screenshot below. Also choose the checkboxes and Levels appropriately.Again, we need to rearrange the sequence.Once we have Totals > Subtotals > lowest level> Members we will get our favorable output.If we preview the final look in the Fullscreen, we can observe that the styling rules are repeating for every dimension member combination.This method will improve the performance by eliminating manual cell styling.Always go for styling rules wherever possible.Hope this blog was helpful, if you have any doubts, you can always drop a comment below.With regards,Siva prakash. Read More Technology Blogs by Members articles
#SAP
#SAPTechnologyblog