Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
imallears
Contributor
Contributor

Expression problems in chart

I have two charts, one hidden on a conditional show.

Dimensions  for both charts are:

Week/Year (This is also the default vie when app is opened)

Name

Day

Expression for Chart A:

if(avg({$<FlagA={'1'},FlagB={'1'}>} HoursIn8HourDay/8)>1,1,
avg({$<FlagA={'1'},FlagB={'1'}>} HoursIn8HourDay/8))

Expression for Chart B: (Hidden. It has a conditional show if Name is selected)

if(sum({$<FlagA ={'1'}, FlagB ={'1'}>} HoursIn8HourDay/8)>1,1,
sum({$<FlagA ={'1'}, FlagB ={'1'}>} HoursIn8HourDay/8))

Listboxes are:

Year, Month, Week, Day and Name  

The chart works if selections are  made in the order  - Year, Month, Week, Name.

If Name is chosen first however the chart is incorrect (as it’s using the sum expression )

Is a hidden chart even required or will one chart do with multiple if statements in an expression?

Thanks in advance!

8 Replies
sunny_talwar

You can create a single chart with if condition such as

If(GetSelectedCount(Name) > 0,

if(sum({$<FlagA ={'1'}, FlagB ={'1'}>} HoursIn8HourDay/8)>1,1,
sum({$<FlagA ={'1'}, FlagB ={'1'}>} HoursIn8HourDay/8)),

if(avg({$<FlagA={'1'},FlagB={'1'}>} HoursIn8HourDay/8)>1,1,
avg({$<FlagA={'1'},FlagB={'1'}>} HoursIn8HourDay
/8)))

But this is beside what the issue is.

Kushal_Chawda

I don't think you required two chart. One can do the trick

imallears
Contributor
Contributor
Author

Unfortunately that creates the same issue.

When Name is selected first, the default chart shows sum rather than average

sunny_talwar

Do you only want the Sum expression when all of the 4 fields have at least one selected value? May be this:

If(GetSelectedCount(Name) > 0 and GetSelectedCount(Year) > 0 and GetSelectedCount(Month) > 0 and GetSelectedCount(Week) > 0 and GetSelectedCount(Day) > 0,

if(sum({$<FlagA ={'1'}, FlagB ={'1'}>} HoursIn8HourDay/8)>1,1,
sum({$<FlagA ={'1'}, FlagB ={'1'}>} HoursIn8HourDay/8)),

if(avg({$<FlagA={'1'},FlagB={'1'}>} HoursIn8HourDay/8)>1,1,
avg({$<FlagA={'1'},FlagB={'1'}>} HoursIn8HourDay
/8)))

imallears
Contributor
Contributor
Author

Thanks, almost have it now.

The calculation for week is incorrect. It should be sum but is showing as average.

sunny_talwar

Not sure I understand, may be you can explain me the logic behind what selections show expression1 and what selections show expression2

imallears
Contributor
Contributor
Author

When there is one Flag A my daily % calculation is correct

When there are two Flag A's my daily Log % total is incorrectly divided by 2

When there are three Flag A's my daily Log % total is incorrectly divided by 3

and so on

sunny_talwar

It is difficult to understand what you are trying to do. Do you have a sample you can share with your expected output?