If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.
IN order to aggregate data I used the following expression:
monthstart(min(Total <CustomerId,LocationId> RegistrationDate))=StartOfMonth,1,0
The data snapshot has been attached (refer to data_snapshot.png)
Initially, I had data for dates for 2016-2017 and the expression above worked perfectly well.
MIN() converted dates to their StartOfMonth equivalent.
However, when I added dates for the first six months of 2018 (see lower part of data_snapshot.png), only those RegistrationDate values which fall on the first of a given Month were accounted for.
in other words out of about a hundred dates which I added for 2018, only 20 are accounted for in the resulting Pivot Table resulting_table.png), while for 2016 and 2017 I get an accurate count for all Customers who registered throughout 2016-2017.
Note: StartOfMonth is product of MonthStart("Date") whereas Date is a column in the Calendar table which contains a range of all dates for 2016-2018 (refer to date_snapshot)
Question: how can I correct the SUM() expression above to ensure that all CustomerIDs for all years are accounted for for all RegistrationDate\s and not just the ones who happened to had registered on the first date of the month?
(Refer expected_result.png which was calculated using flags and SUM())
I am a little confused... what really changed between 2016/2017 and 2018? The dates seems to be randomly spread out in month for 2016/2017 and 2018... why would the expression work for 2016/2017, but not 2018? It seems you understand the difference between the two... would you be able to elaborate on this a little bit more?
Nothing changed between 2016/17, I just added random dates for 2018/01 until 2018/07.
Dates for 2016/17 were also generated at random previously.
The expression worked fine for two yearly periods 2016 and 2017 yet fails to aggregate correctly for the 97 (random) records for the first half of 2018.
I know you mentioned that StartOfMonth is created as a MonthStart field... but may be add MonthStart to StartOfMonth in the expression just to be sure
monthstart(min(Total <CustomerId,LocationId> RegistrationDate))=MonthStart(StartOfMonth),1,0
tried MonthStart(StartOfMonth) and the same output.
I have attached a snapshot (see calendar.png) of qvd which I generated from Calendar table for testing purposes previously.
As one can see StartOfMonth column was getting populated correctly in any case.
I have attached the following images with snapshots of data for 2018:
As I mentioned prev. it is only data for 2018 which is not getting aggregated correctly.
Year(RegistrationDate) & Num(Month(RegistrationDate)) as YearMonth,
lookup('Country','LocationId',LocationId,'Geography') as RegistrationCountry,
Count(CustomerId) as CountOfCust
Year(RegistrationDate) & Num(Month(RegistrationDate));
Would you be able to provide the data you have provided as image as a Excel file? I might be able to load them to see what you mean, because images might take a long time to see what issue you might be having