Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
lailarhc
Creator
Creator

Use different (either Year or YearMonth) fields depending on how many values are selected

Is there a way to divide a year into months whenever a single year is selected in a bar chart?
In other words, I want to use the Year field as the bar dimension whenever multiple years are selected, but I want to use YearMonth if there's only one year selected.

Here's the bar I currently have, using Year as the bar dimension:

lailarhc_0-1637158986015.png

 

Here's what it looks like when a single year is selected:

lailarhc_1-1637159024940.png

 

I want it to look something like this:

lailarhc_2-1637159698670.png

The picture above is what it looks like when I use the YearMonth value. But if I do that and select multiple years, here's what happens:

lailarhc_3-1637159784054.png

 

 

I don't want that. When there are multiple years selected, I want the chart to look like the first image.
How can I accomplish that?

Here's my expression so far:

=if(GetCurrentSelections([Data Fim.autoCalendar.Year]) = 1, if(not IsNull([Lotação atual]), [Data Fim.autoCalendar.YearMonth] ), if(not IsNull([Lotação atual]), [Data Fim.autoCalendar.Year] ))

It doesn't work 😞. It still functions like Year is being used instead of YearMonth when a single year is selected

Thank you in advance

1 Solution

Accepted Solutions
Andrei_Cusnir
Specialist
Specialist

Hello,

 

I believe that the issue relies in the expression that you are using. For example here is my reproduction attempt:

 

This is the expression that I have used:

=If(GetSelectedCount([OrderDate.autoCalendar.Year]) = 1, [OrderDate.autoCalendar.Month], [OrderDate.autoCalendar.Year])

 

This is the outcome that I have when 1 year is selected:

SCREENSHOT

 

This is the outcome that I have when more than 1 years are selected:

SCREENSHOT

 

As you can see, it is working as expected since it shows the Month Dimension only if there is 1 year selected, otherwise it shows the Year as Dimension.

 

However, this is not the same outcome when I have used expression similar to yours:

=if(
    
GetCurrentSelections([OrderDate.autoCalendar.Year]) = 1, 
    if(
        not
IsNull(OrderID), 
       
[OrderDate.autoCalendar.Month]
    ), 
    if(
        not
IsNull(OrderID), 
       
[OrderDate.autoCalendar.Year]
    )
)

 

One year selected:

SCREENSHOT 

 

More than one years selected:

SCREENSHOT

 

As you can see, either I select one year or more than one years, always the Year is shown as Dimension

 

Maybe you can elaborate in detail as to why you have used the additional If statements within the first If statement, so we could suggest other solutions/workarounds

 

Help users find answers! Don't forget to mark a solution that worked for you! 🙂

View solution in original post

3 Replies
Andrei_Cusnir
Specialist
Specialist

Hello,

 

I believe that the issue relies in the expression that you are using. For example here is my reproduction attempt:

 

This is the expression that I have used:

=If(GetSelectedCount([OrderDate.autoCalendar.Year]) = 1, [OrderDate.autoCalendar.Month], [OrderDate.autoCalendar.Year])

 

This is the outcome that I have when 1 year is selected:

SCREENSHOT

 

This is the outcome that I have when more than 1 years are selected:

SCREENSHOT

 

As you can see, it is working as expected since it shows the Month Dimension only if there is 1 year selected, otherwise it shows the Year as Dimension.

 

However, this is not the same outcome when I have used expression similar to yours:

=if(
    
GetCurrentSelections([OrderDate.autoCalendar.Year]) = 1, 
    if(
        not
IsNull(OrderID), 
       
[OrderDate.autoCalendar.Month]
    ), 
    if(
        not
IsNull(OrderID), 
       
[OrderDate.autoCalendar.Year]
    )
)

 

One year selected:

SCREENSHOT 

 

More than one years selected:

SCREENSHOT

 

As you can see, either I select one year or more than one years, always the Year is shown as Dimension

 

Maybe you can elaborate in detail as to why you have used the additional If statements within the first If statement, so we could suggest other solutions/workarounds

 

Help users find answers! Don't forget to mark a solution that worked for you! 🙂
lailarhc
Creator
Creator
Author

@Andrei_Cusnir , I was using the GetCurrentSelections() function instead of the GetSelectedCount() one. Once I used the later, it worked for me.

And as for the additional if statements, it's because I have some null values that I don't want to take into consideration.

Andrei_Cusnir
Specialist
Specialist

Hello,

 

Ah you are right! I missed this small detail! I am glad to hear that the answer has helped you resolve the issue 😊

Help users find answers! Don't forget to mark a solution that worked for you! 🙂