Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Variable YTD Budget

Hi

I am trying to calculate the YTD budget based on the selection of the user.

I have a selection for the months (Jan - Dec).

If no month is selected, the YTD budget should only show up to a given month (set in a variable), which is the current actual. If one or more months are selected, than the sum of the selected should be shown.

I tried the following expression:

=Sum({$<SourceType={'Budget'}, Month={'=If(GetSelectedCount(Month)=0,4,GetSelectedCount(Month))'}>} If(AC3='510',  BalanceLC))


4 in this example is the current actual month. So if no month is selected, I would like to show the sum of the budget values that are <= to 4 (i.e. 1 - 4). If I select a month, I want to show the sum of the selection. The above selection works fine, except that when I don't select a month, it shows me the full year budget instead of the 4 months only.

What is wrong in my expression?

Labels (1)
1 Solution

Accepted Solutions
jagan
Partner - Champion III
Partner - Champion III

Hi,


This should work, if not working attach some sample file and expected output.


If(GetSelectedCount(Month)=0,

Sum({$<SourceType={'Budget'}, Month={4}, AC3={'510'}>} BalanceLC),

Sum({$<SourceType={'Budget'}, AC3={'510'}>} BalanceLC))


Regards,

Jagan.

View solution in original post

4 Replies
jagan
Partner - Champion III
Partner - Champion III

Hi,

Try like this

create a variable

vCurrentMonth = 4

If(GetSelectedCount(Month)=0,

Sum({$<SourceType={'Budget'}, Month={'<=$(=vCurrentMonth)'}, AC3={'510'}>} BalanceLC),

Sum({$<SourceType={'Budget'}, AC3={'510'}>} BalanceLC))


Hope this helps you.


Regards,

Jagan.

Not applicable
Author

Dear Jagan

Thanks, I tried that, yet the result is the same...

jagan
Partner - Champion III
Partner - Champion III

Hi,


This should work, if not working attach some sample file and expected output.


If(GetSelectedCount(Month)=0,

Sum({$<SourceType={'Budget'}, Month={4}, AC3={'510'}>} BalanceLC),

Sum({$<SourceType={'Budget'}, AC3={'510'}>} BalanceLC))


Regards,

Jagan.

Not applicable
Author

Thanks, that does the trick, although it is more complicated that I had hoped for.