Excluding Zeros in Calculated Field (Without Filters) for Dynamic Line Chart in Quick Sight

Hi ,

I’m building a parameter-driven line chart in Quick Sight titled “Average {Parameter} by Brand Trend”, where users can toggle between the following metrics using a parameter $PromoTrendValueParam4 :

  • Average $ Shelf Price
  • Average $ Net Price
  • Average $ Promotion
  • Average % Discount

Below is the current setup we have :


Where :

DynamicPromoTrendValue4 :

ifelse(${PromoTrendValueParam4}="Average $ Shelf Price",avg({shelf_price}),${PromoTrendValueParam4}="Average $ Net Price",avg({net_price}),${PromoTrendValueParam4}="Average $ Promotion",avg({Promotion Value}),(avg(Discount)*100))

DynamicPromoTrend :

ifelse(${PromoTrendParam}="Brand",{brand_name}, {merchant_name})

My goal:

In my line chart, I want to exclude months where Promotion or Discount values are 0 so that those data points are not shown on the chart. However, if Net Price or Shelf Price exists for that same month, I still want those values to be visible. I do not want to use visual filters to achieve this, because applying a filter like “Discount greater than 0” removes the entire month from the chart — including valid Net or Shelf Price data, which I need to keep. My goal is to handle this logic entirely within the calculated field, so that only Promotion and Discount lines skip months with 0 values, while Net and Shelf Price lines remain continuous.

So we want to achieve this by doing changes in the below calculated field :

DynamicPromoTrendValue4 :

ifelse(${PromoTrendValueParam4}="Average $ Shelf Price",avg({shelf_price}),${PromoTrendValueParam4}="Average $ Net Price",avg({net_price}),${PromoTrendValueParam4}="Average $ Promotion",avg({Promotion Value}),(avg(Discount)*100))

Where

Promotion value : {shelf_price}-{net_price} and
Discount : {Promotion Value}/{shelf_price}

I have Tried below calculated field but we are not getting correct values for avg promotions and avg discount :

avg( ifelse( ${PromoTrendValueParam4} = "Average $ Shelf Price", {shelf_price}, ${PromoTrendValueParam4} = "Average $ Net Price", {net_price}, ${PromoTrendValueParam4} = "Average $ Promotion" AND {Promotion Value} = 0, NULL, ${PromoTrendValueParam4} = "Average $ Promotion", {Promotion Value}, ${PromoTrendValueParam4} = "Average % Discount" AND {Discount} = 0, NULL, ${PromoTrendValueParam4} = "Average % Discount", {Discount} * 100, NULL ) )

Where
Promotion value : {shelf_price}-{net_price} and
Discount : {Promotion Value}/{shelf_price}

For E.g. For July 2024 Promotion value should be 1 as it is shelf price - net price (156-155) but it is coming as 42 by above formula same is happening with discounts (for net price and shelf price it is working fine)

Regards,
Nikhil.

Hi @Nikhilburhade,
Did you try already to replace the individual aggregation functions in DynamicPromoTrendValue4 with an ifelse check on 0?
Having something like this in mind: Replacing e.g. avg({shelf_price}) with ifelse(avg({shelf_price})=0,NULL,avg({shelf_price})) and proceeding the same way for the other 3 calculations.

The overall calculated field for DynamicPromoTrendValue4 would then look as follows:

ifelse(
${PromoTrendValueParam4}="Average $ Shelf Price",ifelse(avg({shelf_price})=0,NULL,avg({shelf_price})),
${PromoTrendValueParam4}="Average $ Net Price",ifelse(avg({net_price})=0,NULL,avg({net_price})),
${PromoTrendValueParam4}="Average $ Promotion",ifelse(avg({Promotion Value})=0,NULL,avg({Promotion Value})),
ifelse((avg(Discount)*100)=0,NULL,(avg(Discount)*100)))

In case this does not work in your case, would you mind building an example using an anonymized/mocked sample dataset in the Quick Sight Arena and share it here with the Community so that it’s easier to explore and share back a solution that will work for your specific case. Thanks!

Did this answer your question? If so, please help the community out by marking this answer as “Solution”!

1 Like

Hello @Thomas

Thank you so much for the quick response, formula is working fine with the current setup
Just one quick follow-up:
Is there any setting or feature in Quick Sight that allows us to remove the unnecessary blank space at the beginning of the line chart when data for a selected metric (like Promotion) doesn’t start until later months?

For example:

  • If Promotion values only begin in Dec 2024, the trend line for Promotion should start from Dec 2024 — not from the beginning of the timeline with blank gaps.
  • Meanwhile, if Net Price data is available from Jan 2023, its line should still start from Jan 2023.

Is it possible to achieve this kind of dynamic start point per metric in Quick Sight without using filters? (For X axis)

We do have similar options available on Y- axis

Thank you.

Regards,
Nikhil.

With only NULL values being present for Jun 2023 till Nov 2024, I would have expected those months not to show up in your charts. When I quickly reproduced a similar setup on my end, it just started the X-axis with the first month for which I had non-NULL values to visualize. Do you get non-NULL values back for Jun 2023 when exporting it for example to CSV?

Here is an example export for a similar calculation that is visualized as a line chart in the following way:

The x-axis starts with Jun 2020, even though the export also includes rows for Jan-May 2020 with NULL/empty cells for those months in the sum_sales column.

Order Date sum_sales (CUSTOM)
01.12.23 00:00 189.6742
01.11.23 00:00 251.2896
01.10.23 00:00 257.5952
01.09.23 00:00 195.44
01.08.23 00:00 282.1838
01.07.23 00:00 214.2848
01.06.23 00:00 206.2382
01.05.23 00:00 175.5816
01.04.23 00:00 202.5879
01.03.23 00:00 237.4844
01.02.23 00:00 193.1763
01.01.23 00:00 275.9453
01.12.22 00:00 277.8211
01.11.22 00:00 220.3547
01.10.22 00:00 297.1743
01.09.22 00:00 201.4036
01.08.22 00:00 184.8086
01.07.22 00:00 193.1696
01.06.22 00:00 195.2002
01.05.22 00:00 255.3652
01.04.22 00:00 230.874
01.03.22 00:00 317.9268
01.02.22 00:00 278.8745
01.01.22 00:00 208.3425
01.12.21 00:00 237.087
01.11.21 00:00 234.4832
01.10.21 00:00 189.1862
01.09.21 00:00 220.4638
01.08.21 00:00 232.0649
01.07.21 00:00 205.4666
01.06.21 00:00 179.6905
01.05.21 00:00 206.3814
01.04.21 00:00 213.72
01.03.21 00:00 280.625
01.02.21 00:00 186.7407
01.01.21 00:00 313.3461
01.12.20 00:00 250.1641
01.11.20 00:00 247.2601
01.10.20 00:00 197.82
01.09.20 00:00 305.1393
01.08.20 00:00 182.4148
01.07.20 00:00 237.3873
01.06.20 00:00 256.2602
01.05.20 00:00
01.04.20 00:00
01.03.20 00:00
01.02.20 00:00
01.01.20 00:00
1 Like

Hello @Thomas

Thank you for your response.

I have tested this using a manual table, and for some reason, I’m still seeing NULL values plotted on the graph. As shown in the image below, the field DynamicPromoTrendValue4_Test (our newly created calculated field) is returning NULL for the selected parameter “Average $ Promotion” when corresponding Promotion Value is 0 which is correct behavior and This suggests that the current logic is correctly excluding zero values, but these NULLs are still being visualized as gaps in the line chart (As shown in the image below).

Ideally, NULL values are not plotted on the graph. Also, when I export the table to Excel, I see NULL values present—just like in the example shown above so not sure why ‘NULLS’ are getting populated on the graph.
You can checkout my current visual setup in my first post (Jul 9, 1:39 PM)

Regards,
Nikhil

Thanks Nikhil,
In your first post, the line chart is using field DynamicPromoTrendValue4, is this now the third column in the table (which still includes 0 values) or did you adjust the line chart visual to leverage field DynamicPromoTrendValue4_Test? How does the CSV export of the line chart visual look like?

1 Like

Hello @Thomas

Thank you for your quick reply.

1] I am using DynamicPromoTrendValue4_Test (Newly created field) as shown in the image below:

DynamicPromoTrendValue4_Test:

DynamicPromoTrend:

2] And if i export this line chart to the CSV then i am getting Null entries where we have promotion value as 0 as shown in the image below :

But still our line chart is not excluding that gap for Null values and showing as it is.

Regards,
Nikhil.

Hi Nikhil,
The reason why it behaves this way in your case is because of the addition of a field in the “Color” section. I’ll mark this topic here as feature request to capture your need for such support.

In case you have a limited number of static values in DynamicPromoTrend (which doesn’t seem to be the case), you could split your value into multiple separate values and add each to the “Value” section of the visual. In such case, it still is able to hide all the NULL entries on the left side of the x-axis.

1 Like

Hi Thomas,

Thank you so much for the detailed explanation and for marking this as a feature request — I really appreciate your quick response and the clarity provided.

Your explanation makes complete sense now. I understand that the presence of a field in the “Color” section is causing NULLs to be plotted on the graph. Since our use case involves dynamic grouping with a large number of brands and retailers under DynamicPromoTrend, we’ll proceed with the current setup for now. That said, it’s great to have visibility into the root cause and a potential workaround if the need arises.

Thanks again for the support!

Best regards,
Nikhil