# Build an INDEX column which denominator is a dynamic parameter (base 100)

Hello, I need to build a pivot table in QuickSight, and I’m seeking advice on how to structure a dynamic calculation.

Objective:

1. Rows: A selection of countries defined by a parameter [\${CountrySelection}]
2. Columns: The result of the calculation `avg(price) / avg(price, [\${baseCountry}])`.

I intend to read the selected countries’ positioning as an index of the base country

Context:

• The parameter `\${baseCountry}` is defined by the user and represents one of the countries from the selection.

Challenge: I am encountering difficulties constructing the calculated field for the desired result. Specifically, I’m facing challenges in creating a dynamic calculation that adjusts based on the selected `\${baseCountry}` parameter.

Formula Attempted:

avg(price) / avg(price, [\${baseCountry}])

However, I’ve run into errors, and there are no values resulting from this calculated fields besides when for baseCoutry (= 1)

Any clue on how to achieve this ?

(as I post this message on Dec 31st, my best wishes of a happy new year for all of you)

1 Like

Hi,

Happy new Year.

This is my first community support of 2024.

This document will help you, this is the same scenario you are looking for.

Regards,
Naveed Ali

2 Likes

thank you @Naveed Naveed

avg(decimal , [group-by level ])

I struggle to make it work with the [group-by level] being a Parameter modified by the User as a Control

Hi Bek-
Did you solve your issue? If not, here’s a few thoughts. First, I can get a parameter to successfully work in the group variable using this formula: avg(Sales,[\${country}]). It appears you are trying to take the avg of all countries and then divide it by the avg of the selected country in the parameter. I would assume that parameter is driving a filter on your visual. If so, the avg (price) in the numerator of your visual is only taking the avg price of the data in the visual (which is filtered to that single country). If you still need assistance, can you share more details so we can help. Thanks!

Thank you for your help Kellie,

actually in numerator I have a selection of 10-12 countries, each individually displayed in their respective row, and in column is the corresponding avg(sales) for each country
now, in denominator, I am aiming at using a Parameter controled by my Users. This parameter selects the avg(sales) value of one of the 10-12 countries.
as a result all 12 countries are compared to the chosen one.

eg.
avg sales
countryA = 2000
countryB = 2200
countryC = 1900
countryD = 2500

if with the control/parameter, my User selects CountryA as a base, then INDEX column becomes
countryA = 100
countryB = 110
countryC = 95

if User changes the base, and selects countryC as a base, then the Index column switches to
A = 105
B = 116
C = 100
D = 132

I struggle to make it work. I start to have doubts about the filters I added or the setting of my paramater.

Hello @bek, were you able to resolve the issue you were facing in QuickSight? If not, I think utilizing LAC-W functions might work better for this situation.

If your filter is altering the values that you are wanting to use, this could help you achieve the output without being impacted by the visual filter. It would look something like this:

`avgOver({price}, [], PRE_AGG)/avgOver({price}, [\${baseCountry}], PRE_AGG)`

You can also try swapping PRE_AGG with PRE_FILTER to see if there are still issues with the result. Another consideration, add the numerator and denominator as their own calculated fields as well and include them on the table to see if you are getting the expected values for each. That will help target the issue and will provide some more information. Let me know if this helps!

1 Like