Jump to content

I need support to tweak a custom expression that should cumulate Sales values only until current week displaying the target line intact until last week of the quarter.


Samit
Go to solution Solved by Vanessa Virginia Sucre Gonzalez,

Recommended Posts

Here is the expression that I am working with:

Sum(if([Cal Week (Sales)]<='${Snapshotweek1}',[Sales Net Net USD CKF])) then Sum([Value]) OVER (AllPrevious([Axis.X])) AS [Cummulative Sales Net Net USD]

Issue is it is showing cumulative values even for the future weeks (it should show until week 202428 only). Current week is defined by the document property parameter ${Snapshotweek1}.

I am using external database connection type here. Please advise how can I edit this expression in order to limit displaying cumulative value until snapshot week 202428 only and target line until 202439 as is.

 

image.png.0e90db9b3c75af85435e2446101f941d.png

Link to comment
Share on other sites

Hi Samit

I suspect this issue is related to the usage of the "THEN" expression. Usually THEN is used to optimize the query sent to the database and therefore, in your case, might lead to some side effects. especially when your data source is not in-memory but external.

Can you try this one instead? 

new expression. ::::: Sum(if([Cal Week (Sales)]<='${Snapshotweek1}',[Sales Net Net USD CKF]))  OVER (AllPrevious([Axis.X])) AS [Cummulative Sales Net Net USD]

Let me know if this worked

Link to comment
Share on other sites

52 minutes ago, Olivier Keugue Tadaa said:

Hi Samit

I suspect this issue is related to the usage of the "THEN" expression. Usually THEN is used to optimize the query sent to the database and therefore, in your case, might lead to some side effects. especially when your data source is not in-memory but external.

Can you try this one instead? 

new expression. ::::: Sum(if([Cal Week (Sales)]<='${Snapshotweek1}',[Sales Net Net USD CKF]))  OVER (AllPrevious([Axis.X])) AS [Cummulative Sales Net Net USD]

Let me know if this worked

Hi Olivier, no it says the error: Could not find function 'AllPrevious'. This error can only be removed by adding THEN keyword with Sum([Value]) expression.

Link to comment
Share on other sites

37 minutes ago, Vanessa Virginia Sucre Gonzalez said:

Hi Samit,

You could try something like this :

Max(case  when [Cal Week (Sales)]<='${Snapshotweek1}'  then Sum([Sales Net Net USD CKF]) OVER (AllPrevious([Axis.X])) else null end)

This will set to null all values after Snapshotweek1 and keep those prior to Snapshotweek1

Let me know if it works for you :) 

Hi Vanessa, error: Could not find function 'AllPrevious'.

Link to comment
Share on other sites

19 hours ago, Vanessa Virginia Sucre Gonzalez said:

@Samit Let me know if it works for you

Terrific! It worked Vanessa with tiny tweak (as I alias X axis as Week). Here is the final expression: Sum([Sales Net Net USD CKF]) THEN If([X.Week]<='${Snapshotweek1}',Sum([Value]) OVER (AllPrevious([Axis.X])),null)

Thank you so much Vanessa for quick guidance!

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...