Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Sebastian_Dec
Creator II
Creator II

Pivot color background depending on the avg value of dimension level

Hi, how to color the background depending on the dimension level?

For example, I have dimensions in a pivot table:
GT Gessica -> nazwa dostawcy -> Nazwa Sklep -> Artykuł.
And measures value like TMP.

My background color expression is:

If(Dimensionality()=1 and (sum(TMP))<(avg(total TMP)),RGB(255,156,156),
If(Dimensionality()=2 and (sum(TMP))<(avg(TMP)),RGB(178,29,29)
))		

 

I would like the average TMP value to be calculated for a given dimension.

For example:
dimension GT Gessica have avg TMP 18.30%, I have value 16.49% that is less than avg TMP and is in red (Its work because is calculate Total values).
dimension Nazwa dostawcy for GT Gessica: 11 SPOŻYWCZE SŁONE have avg TMP 16.49%, I have value 0.29% for 10055 CHABER that is less than avg TMP for this dimension and should be in red <- this not working, I don't know how to approach this

 

Sebastian_Dec_0-1703844518432.png

 

Thanks & Regards,
Please close the thread by marking correct answer & give likes if you like the post.
Labels (5)
1 Solution

Accepted Solutions
vinieme12
Champion III
Champion III

you need to specify the exact dimension field name to scope the total on as below

 

avg(total TMP) // will give overall total

avg(total <Field1> TMP) // will give overall total at Field1 level  including the angle bracket

avg(total <Field1,Field2> TMP) // will give overall total aggregated based on combination of Field1 & Field 2

 including the angle bracket

 

avg(total TMP)  // will give overall total

avg(total <Field1> TMP)  // will give overall total at Field1 level

avg(total <Field1,Field2> TMP)  // will give overall total aggregated based on combination of Field1 & Field 2

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

8 Replies
vinieme12
Champion III
Champion III

you need to specify the exact dimension field name to scope the total on as below

 

avg(total TMP) // will give overall total

avg(total <Field1> TMP) // will give overall total at Field1 level  including the angle bracket

avg(total <Field1,Field2> TMP) // will give overall total aggregated based on combination of Field1 & Field 2

 including the angle bracket

 

avg(total TMP)  // will give overall total

avg(total <Field1> TMP)  // will give overall total at Field1 level

avg(total <Field1,Field2> TMP)  // will give overall total aggregated based on combination of Field1 & Field 2

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Sebastian_Dec
Creator II
Creator II
Author

Wow, thank you, it works!

Sebastian_Dec_0-1704186022965.png

 

Now I need to use colors, but the initial code to show the values looks like this:

=
If(Dimensionality()=1, (avg(total obrot_netto_prom)/avg(total obrot_netto_total)),
If(Dimensionality()=2, (avg(total <hid_GT> obrot_netto_prom)/avg(total <hid_GT> obrot_netto_total)),
If(Dimensionality()=3, (avg(total <DostawcaId> obrot_netto_prom)/avg(total <DostawcaId> obrot_netto_total)),
If(Dimensionality()=4, (avg(total <skrot_sklep> obrot_netto_prom)/avg(total <skrot_sklep> obrot_netto_total)),
))))

 

Thanks & Regards,
Please close the thread by marking correct answer & give likes if you like the post.
vinieme12
Champion III
Champion III

 

try below

 

=
If(Dimensionality()=1, (avg(obrot_netto_prom)/avg(total obrot_netto_total)),
If(Dimensionality()=2, (avg( obrot_netto_prom)/avg( total <hid_GT> obrot_netto_total)),
If(Dimensionality()=3, (avg( obrot_netto_prom)/avg( total <hid_GT,DostawcaId> obrot_netto_total)),
If(Dimensionality()=4, (avg( obrot_netto_prom)/avg(total total <hid_GT,DostawcaId,skrot_sklep> obrot_netto_total)),
))))

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Sebastian_Dec
Creator II
Creator II
Author

Yes, its changed.
like You wrote:


@vinieme12 wrote:

 

avg(total <Field1> TMP) // <one field> will give overall total at Field1 level including the angle bracket

avg(total <Field1,Field2> TMP) // <multi filed> will give overall total aggregated based on combination of Field1 & Field 2


At this moment I don't know if I want to use one field or many fields.

It's good that this is possible, but can You give some examples of when one field is used and when many fields are used?

The table is intended to show which stores/suppliers in a given category lag behind the average.

 

Sebastian_Dec_0-1704186651971.png

 

Thanks & Regards,
Please close the thread by marking correct answer & give likes if you like the post.
vinieme12
Champion III
Champion III

can you post some sample data?

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Sebastian_Dec
Creator II
Creator II
Author

Yes, please.
2 department (hid_GT), 3 suppliers (DostawcaId), 3 stores (skrot_sklep) and articles (Product).

TMP = obrot_netto_prom/obrot_netto_total

 

Thanks & Regards,
Please close the thread by marking correct answer & give likes if you like the post.
vinieme12
Champion III
Champion III

as below?

vinieme12_0-1704262313228.png

 

Dimension:

DostawcaId

skrot_sklep

Product

 

Measures:

=Avg(obrot_netto_prom)

BackgroundExpression

=if(
Avg(obrot_netto_prom)
<
Pick(Dimensionality()
,Avg(Total obrot_netto_total)
,Avg(Total <$(=GetObjectDimension(0))> obrot_netto_total)
,Avg(Total <$(=GetObjectDimension(0)),$(=GetObjectDimension(1))> obrot_netto_total)
)
,RGB(255,156,156)
,RGB(178,29,29))

 

 

 

Avg(obrot_netto_total)

Avg(total <$(=GetObjectDimension(0))> obrot_netto_total)

Avg(total <$(=GetObjectDimension(0)),$(=GetObjectDimension(1))> obrot_netto_total)

Dimensionality()

 

 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Sebastian_Dec
Creator II
Creator II
Author

I have some problem with BackgroundExpression:

=if(
Avg(obrot_netto_prom)
<
Pick(Dimensionality()
,Avg(Total obrot_netto_total)
,Avg(Total <$(=GetObjectDimension(0))> obrot_netto_total)
,Avg(Total <$(=GetObjectDimension(0)),$(=GetObjectDimension(1))> obrot_netto_total)
)
,RGB(255,156,156)
,RGB(178,29,29))

 

Error:

Sebastian_Dec_0-1704263441515.png

 

The Pick() function should be so long?

Sebastian_Dec_1-1704263478537.png

 

Thanks & Regards,
Please close the thread by marking correct answer & give likes if you like the post.