Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Jérôme5625
Creator
Creator

Problem table graph with set analysis (current month, current year...)

Thank you for your last support for my last question.

but I've been reading several forums over the last two days but I can't seem to get what I want.
Attached is a screen printout where the results for the current month and the current year do not work.

In fact, when I choose a date (field: date.autoCalendar.date) with a filter (example 25/07/2023), the results in my table remain identical because I've filtered on the date to be chosen and so it points to that date and not to the full database

formula used:

Count({<Date = {"$(='>=' & date.autoCalendar.Date(MonthStart(Max(date.autoCalendar.Date))) & '<=' & date.autoCalendar.Date(Max(date.autoCalendar.Date)))"}>}data_id)


what's more, if someone finds the solution, which I hope they will, how can I get the result for the previous month? do I add -1 to my formula?
Thank you for your help.

Labels (3)
1 Solution

Accepted Solutions
Jérôme5625
Creator
Creator
Author

thanks for your last answer.

I have checked a lot of time the format of the field date.autocalendar.date but i don't seen anything.

I have start again the formula and I have found the solution:

Count({<[date.autoCalendar.Date]={">=$(=MonthStart([date.autoCalendar.Date]))"}*{"<$(=MonthEnd([date.autoCalendar.Date]))"}>}[data_id])

 

I use the intersection of the date with * and the result is well!!

 

Have a nice day

View solution in original post

10 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Jerome,

There are several issues there... Let me uncover some and give you some ideas:

1. When you add a Date condition to your Set Analysis, such as Date = {...}, that effectively overrides your Date selection in a filter pane. If you want the formula to be responsive to your date selection, you should formulate it in a different way - for example, use *= instead of a simple =. This way, you will get an intersection between your selected dates and the results of the Set Analysis condition.

2. It looks like you are using the automatic calendar. In this case, you should use a fully qualified field name in your set analysis filter:

date.autoCalendar.Date = {...}

3. Your search condition contains the following:

date.autoCalendar.Date(MonthStart(Max(date.autoCalendar.Date))) 

This is syntactically incorrect - the function Date() that you are applying should not be fully qualified. In fact, it's not needed either - the function MonthStart already returns a fully formatted date. So, you can replace that with this:

MonthStart(Max(date.autoCalendar.Date)))

4. Then, you need to decide if this formula should return results for the last selected month or for the current month, disregarding of the selections. For the latter, you should ignore user selections when you calculate Max of date:

MonthStart(Max({1} date.autoCalendar.Date)))

5. When using Dates in Set Analysis search expressions, they need to be enclosed in single quotes, otherwise Qlik will try to calculate them as a mathematical expression.

To bring it all together, I'd formulate the formula as follows. It will return results for the selected month (all dates in the highest month that was selected, not only for the selected date):

Count({<date.autoCalendar.Date = {">= '$(=MonthStart(Max(date.autoCalendar.Date)))'<='$(=MonthEnd(Max(date.autoCalendar.Date)))'"}>}data_id)

Now, with this in mind, the same formula for the previous month would look like this (-1 is the second parameter for the functions MonthStart and MonthEnd:

Count({<date.autoCalendar.Date = {">= '$(=MonthStart(Max(date.autoCalendar.Date), -1))'<='$(=MonthEnd(Max(date.autoCalendar.Date), -1))'"}>}data_id)

 

Join us at the Masters Summit for Qlik in Orlando or in Dublin, and learn advanced Set Analysis  directly from me, along with data modeling, scripting, visualizations and peformance, delivered by some of the best Qlik experts in the world!

 

 

Jérôme5625
Creator
Creator
Author

Hi Oleg,

Thank you very much for your reply, which helped me understand the dates.
However, I've just put in the suggested formula (for example, for the previous month) and the result remains at 0 after choosing a date ( 25/074/2023).
Do you have any idea as to the cause? An error in the formula?
Attached are two screenshots
Thank you

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

The formula looks correct to me, and it renders proper dates, as seen at the bottom of the expression editor. Do you have data for the month of June? Could it be that other selections exclude all the data for June? You can troubleshoot it by creating a detailed table with Date as a dimension and verifying what data is available. Also verify the formatting of the Date field in the derived calendar - does it look the same way as the date in the Set Analysis filter?

Jérôme5625
Creator
Creator
Author

see new screenshots to describe my application. 

I have data for June, but it's not counted.

we can see that the start and end of month dates have been found.
It's as if it can't count.
Data_Id works well because I can count its count as you will see in the second column...
If you see anything that needs to be changed, let me know.
Thanks in advance for your support

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Well... Ideally, I'd like to see your app. If you can't post it, try to troubleshoot your data by yourself - for example, what would you see if you selected a date in June and used the formula for the current month? Would you see the correct counts?

Also, what other selections are you making, that could exclude the June data from the possible values?

Jérôme5625
Creator
Creator
Author

Oleg,

What I don't understand is that, for example, I can calculate the quantity using the second column (count(data_id)):

e.g. "qty 3 for the commerce" but 0 with the monthly formula (at the right side of the table)
That's why I was wondering about the syntax.
Thanks

an idea?

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Well, these are completely different calculations, because of the Set Analysis filters - the quantity column shows results for the selected Date in July, while the count should be counting corresponding data in June. When Date is one of the dimensions, it's expected to see zeroes there, because no data from June is associated with a July date. This is why I suggested to use the "Current month" formula with June dates for data troubleshooting.

I still believe that the formula is correct, but the data associations or formatting or other selections are causing the perceived issue. Dig into the data, and you will find the issue.

 

Jérôme5625
Creator
Creator
Author

attached the screenshot in June. we have some datas. 

what do you think when you write 'format the data'?
Are you thinking of a problem with the date format?
Shouldn't we convert the date into a date to make sure that the formula sees that date.autoCalendar.Date is actually a date?

 

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

When I say "Date Format", I mean the specific format of the Date fields.

In the last screenshot that you shared, you are filtering the Month field, using the values of the Date fields. This is a possible mismatch of formats - the Month field usually has a different format than the Date fields.