Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
jason_nicholas
Creator II
Creator II

Year to Date set analysis

I have searched a number of threads to determine the set analysis function for displaying year to date data. I don't fully understand how this function works, and I am not getting the expected results. I would appreciate feedback and corrections to my approach.

Here is the function I am using

Count(DISTINCT{$<[Event Flag]={'Event Flag'},Status={'Active'},[Test Filter]={'Remove Testing'},Year={$(=Max(Year))},Month={"<=$(=max(Month))"}>}[Booking ID])

I have region as a dimension, and the goal is to show a pie chart distribution of the number of [Booking ID]s that fit a specific description per region, to date (or potentially through the last completed month). When I add in the highlighted year to date function above, the chart totals are still measuring the entire year instead of year to date.

My date field is loaded by year, month, and day separately. In addition, all of the data in this report only includes the current year, so maybe I can remove the Year setting altogether?

Can someone explain in plain text how this function is supposed to work? How does it look at the current date (or date of last update)? It is my understanding that max(month) is looking for the maximum month listed in the data, but my data source looks ahead as well as behind, so the max(month) is always going to be December.

Is there a different function I could use to measure the number of bookings in my report that occur before a set date (today, the last reload date, or the end of the previous month)?

1 Solution

Accepted Solutions
sunny_talwar

No problem at all. While we are here, I am going to provide you one other way to approach this problem assuming your application reloads everyday

LOAD Date([Booking Date]) as [Booking Date],

    Year([Booking Date]) as Year,

    Month([Booking Date]) as Month,

    NUM(Month([Booking Date])) as NumMonth,

    Day([Booking Date]) as Day,

    If([Booking Date] <= Today() and Year = Year(Today()), 1, 0) as Flag

and then you need just this:

Count(DISTINCT{$<[Event Flag] = {'Event Flag'}, Status = {'Active'}, [Test Filter] = {'Remove Testing'}, Flag = {1}>}[Booking ID])

View solution in original post

20 Replies
sunny_talwar

I would recommend to create a Month field with numeric representation

LOAD Month,

    Num(Month) as NumMonth

    ...

FROM ...

next if you need the YTD as of the current month, Max(Month) isn't going to work. Instead use Today's month

Count(DISTINCT{$<[Event Flag] = {'Event Flag'}, Status = {'Active'}, [Test Filter] = {'Remove Testing'}, Year = {$(=Max(Year))}, Month = {"<=$(=Num(Month(Today())))"}>}[Booking ID])

jason_nicholas
Creator II
Creator II
Author

This works well. I had to use a preceding load for NumMonth, because my primary load uses

LOAD

Month([Booking Date] as Month

But, once I got that, the function worked. I am not fully clear on the syntax, particularly in the use of the parentheses.

I see that it says "select the year that is the maximum year in the data", and select the month (by number) that is less than or equal to today's month number, but what does the additional () mean? I have seen it in a number of threads, and I can't quite get what it is for.

sunny_talwar

You don't have to do preceding load, you can do this

LOAD [Booking Date],

     Month([Booking Date]) as Month,

     Num(Month([Booking Date])) as NumMonth

I see that it says "select the year that is the maximum year in the data", and select the month (by number) that is less than or equal to today's month number, but what does the additional () mean? I have seen it in a number of threads, and I can't quite get what it is for.

Additional ()? Where?

jason_nicholas
Creator II
Creator II
Author

A further question:

Am I correct in assuming the function will give me the total through the end of the current month? Or would it be accurate to the day?

My data has 5 bookings in January, and 1 in February. The February booking has already happened, so I get an accurate result of '6'. Would this correctly calculate as '5' if the February booking were in the future?

sunny_talwar

This will give you the correct result to the end of the month.

=Num(Month(Today()))


will be 2 regardless if it is 1st Feb or 28th Feb. So, all data for Feb will be included. Do you want just until today?

sunny_talwar

For accuracy of today's date, I would use this

Count(DISTINCT{$<[Event Flag] = {'Event Flag'}, Status = {'Active'}, [Test Filter] = {'Remove Testing'}, Year = {$(=Max(Year))}, Month, [Booking Date] = {"<=$(=Date(Today(), 'DateFieldFormatHere'))"}>}[Booking ID])

jason_nicholas
Creator II
Creator II
Author

I think I misunderstood how the statement works. I though the Month (in bold, below) was a reference to the field I created above it. Now I understand it is a function in itself. Thanks for the clarity

LOAD [Booking Date],

     Month([Booking Date]) as Month,

     Num(Month([Booking Date])) as NumMonth

the statement Today()    which is then followed by the three parentheses closing out the function. I don't get what the () at the end of Today (or other functions I have seen it in) means.

jason_nicholas
Creator II
Creator II
Author

my date field is simply called DAY. Just to confirm I use correct syntax, would it be:

Count(DISTINCT{$<Location={'External'},Status={'Active'},[Test Filter]={'Remove Testing'},Year = {$(=Max(Year))}, Month, [Booking Date] = {"<=$(=Date(Today(), Day))"}>}[Booking ID])

this gave me the correct result, but I just want to be sure I fully understand what I am putting. This additional syntax will take some digging to comprehend.

I don't know where I'd be without this message board. Thank you all

sunny_talwar

Booking Date is just a Day? Not sure I understand... Can you share a screenshot of how Booking Date looks? Also, look here:

Dates in Set Analysis