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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Amit_B
Creator II
Creator II

If condition not working properly

Hi,

I have a container with 2 charts that are displayed based on a specific condition. At any given time, only one chart will be shown.
The first chart shows income vs expenses, shows the last 3 months based on the maximum date.
The second chart shows income vs forecasted income, the data displaying according to the selected period.
Both charts use the same dimension - Date.
Both charts are functioning and displaying accurate data.

I trying to "merge" them and add the condition to the measures.
The problem is that when I want to display "the first chart", it shows data of the second chart and only for the current month, while the others show 0.

This is one of the measures:
If(Count(distinct YearMonth) <> 1,
     [Forecast], // chart 2
     {<Date={">=$(v3Months_StartDate)<=$(v3Months_EndDate)"}, Year=, Quarter=, MonthID=>} [Expenses] // chart 1
) / 1000000

The condition refers to the number of selected months. Even though one month is selected (count(distinct YearMonth) = 1), the forecast is displaying instead of the expenses.
Why is this happening?

I would appreciate your help.
Thanks.

Labels (5)
3 Replies
Or
MVP
MVP

Did you actually add count(distinct YearMonth) as a measure to confirm it gets 1?

If so, if you just use If(count(distinct YearMonth)>1, 'F','E'), does that work as expected?

Is [Forecast] valid for placing within an If() statement? Is [Expenses]?

Amit_B
Creator II
Creator II
Author

Yes to all.

Each part of the measure works properly separately.
When connecting all together under If condition, it doesn't.

Or
MVP
MVP

Quite odd, because given the context you've provided, I would expect it to always show expenses. Since you have Date as a dimension, I would expect Count(distinct YearMonth) placed within a measure to always return 1, since each date is associated with a single YearMonth (I think this would typically be Count(total Distinct YearMonth) to get the "expected" result). But this would explain the opposite outcome...