How to correctly sum the Order total based on year

Why my below calculated field is not giving the expected output

ifelse(
max({Effective Date}) >= ${FromDate} AND
max({Effective Date}) <= ${ToDate} AND
max({Commitment Date}) >= ${FromDate} AND max({Commitment Date}) <= ${ToDate},
sum({Untaxed Amount Invoiced}),0
)

It is giving 0 as the output but when I am adding Sale order name column to the view then only the amount is coming but that is also not correct.

I have 2 tables

  1. Sales Order (Fields)
    Name
    Effective Date
    Commitment Date
    Sales Order Lines (One2many)

  2. Sales Order Lines (Fields)
    Untaxed Amount Invoiced

I want the below 2 column as the output in the table visual based on FromDate & ToDate filter selected

Commitment Date (Year)
Sum of Untaxed Amount Invoiced

Please let me know if still need anything.

Hello @NirmalSingh, just to clarify, the output for your 2nd table would only contain 2 columns and 1 value for each, am I correct?

If so, I wonder if this would be better displayed in a KPI rather than a table visual. Either way, it seems your calculated field may need a slight adjustment. I think if we avoid running the sum in the ifelse statement, but rather aggregated the resulting value in the visual, you may achieve a better result. Now, as I am sure you have experienced, you can’t compare max of Effective Date in the if statement and then return an unaggregated Untaxed Amount, but we should be able to bypass that. I will return an option below:

ifelse(
maxOver({Effective Date}, [{Order Name}], PRE_AGG) >= ${FromDate} AND
maxOver({Effective Date}, [{Order Name}], PRE_AGG) <= ${ToDate} AND
maxOver({Commitment Date}, [{Order Name}], PRE_AGG) >= ${FromDate} AND maxOver({Commitment Date}, [{Order Name}], PRE_AGG) <= ${ToDate},
{Untaxed Amount Invoiced},
0 --Could also consider replacing this value with NULL so it is excluded
)

Alternatively, we could wrap this into a sumOver statement:

sumOver(
ifelse(
maxOver({Effective Date}, [{Order Name}], PRE_AGG) >= ${FromDate} AND
maxOver({Effective Date}, [{Order Name}], PRE_AGG) <= ${ToDate} AND
maxOver({Commitment Date}, [{Order Name}], PRE_AGG) >= ${FromDate} AND maxOver({Commitment Date}, [{Order Name}], PRE_AGG) <= ${ToDate},
{Untaxed Amount Invoiced},
NULL
), [], PRE_AGG)

One of these 2 options should get you the expected result. I will mark my response as the solution, but let me know if you run into any errors on implementation. Thank you!

Thank you for the response.

But this is still not working. Sum of Untaxed Amount Invoiced is coming so much high after using this.

Note :
I don’t want to add or any other fields in the table visual only Commitment Date (Year)
& Sum of Untaxed Amount Invoiced.

Example:
Commitment Date (Year) Sum of Untaxed Amount Invoiced
2022 $ 2345
2033 $ 12345
2024 $ 87242

Hello @NirmalSingh, when you add this calculated field to a visual, make sure you aggregate it as a min value. What will happen with the LAC-W aggregated fields is they will return the same value on many rows. If you aggregate it as a min, it should return the value you are looking for,

Hello @WLS-DM Thank you again for the response.

Again the same Issue as I am using below code as shared by you

sumOver(
ifelse(
maxOver({Effective Date[Sales Order Dataset]}, [{Sales Order #}], PRE_AGG) >= ${FromDate} AND 
maxOver({Effective Date[Sales Order Dataset]}, [{Sales Order #}], PRE_AGG) <= ${ToDate} AND 
maxOver({Commitment Date}, [{Sales Order #}], PRE_AGG) >= ${FromDate} AND maxOver({Commitment Date}, [{Sales Order #}], PRE_AGG) <= ${ToDate}, {Untaxed  Amount Invoiced, EUR}, NULL), [], PRE_AGG)

And sharing the screenshot for your reference.

Actual Shipments will always be less then planned shipments & on my case for Year 2023 it should be around 16-17 million.

Waiting for your response.

Thanks in Advance.

Hello @NirmalSingh, it seems like our first calculated field is closer than the 2nd. It would be easier for me to resolve this if you add a demo version of the analysis in Quick Sight Arena so I can test the calculated fields on my own. It is difficult to debug when I don’t have matching data to test with or if I am unable to see how the data is formatted.

Hi @WLS-DM Thank you again for the response.

I have created the analysis in Quick Sight Arena. Did I have to share that with you? or you can easily access it.

For me when I tried to export in .csv Untaxed Amount Invoiced, EUR is not coming correct as I used sum in the visual. What should I have to use? as it should be more & less same as Amount Sold, EUR

As I described earlier :

I have 2 tables

**Sales Order (Fields)**
Name
Effective Date
Commitment Date
Sales Order Lines (One2many)

**Sales Order Lines (Fields)**
Untaxed Amount Invoiced

Please let me know if still you need anything.

Thank you in Advance.

Hello @NirmalSingh, if you save it as a dashboard in Quick Sight Arena and go to the share icon, you can get the link and post it in your response. That would allow me to view it and test some solutions on my end.