Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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:
Here's what it looks like when a single year is selected:
I want it to look something like this:
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:
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
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:
This is the outcome that I have when more than 1 years are selected:
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:
More than one years selected:
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
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:
This is the outcome that I have when more than 1 years are selected:
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:
More than one years selected:
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
@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.
Hello,
Ah you are right! I missed this small detail! I am glad to hear that the answer has helped you resolve the issue 😊