Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Rocky6
Creator
Creator

Value For Each Month Last Date

Hi All,

I have requirement  i am using set as sum(final Amount) to show values for all month in a table.

But my requirement is in that table i should show values of each month last date.

Say if user selects march field it should display total values of 31st March  end value not the whole month value and should be same for all months. 

My date field is Date.

I tired with MonthEnd function but i am not getting the values.

 

Labels (4)
20 Replies
marcus_sommer

Within the calendar you may create a flag like:

if(Date = floor(monthend(Date)), 1, 0) as MonthendFlag

and then using it within the expression:

sum({< MonthendFlag = {1}>} Amount)

Rocky6
Creator
Creator
Author

@marcus_sommer  thanks its showing for all month last date. let us  consider this month we have data till 27 april and some months we have data for till 29th of that month . so how to bring up this values in the table. 

In simple the table should give me value for the  day which is last in that month .

Kushal_Chawda

@Rocky6  create a calendar first.

Calendar:
LOAD Date,
MonthYear,
Quarter
....

left join(Calendar)
LOAD MonthYear,
date(max(Date)) as Date,
1 as LatestDateFlag
resident Calendar
group by MonthYear;

Prem0212
Creator
Creator

This expression is working for me 

 

Prem0212_0-1682592803607.png

 

Rocky6
Creator
Creator
Author

@Prem0212  its working for me also but i need to show this month value as 27 April  as i have data till 27 April . 

The expression is showing for every month 31 or 30. 

 

marcus_sommer

You need to elaborate more what do you want to display and how the data look like and from where they are coming.

Are the logic refers to calendar-dates the above will in general work and might just need a few adjustments, for example for the current month which might be done with another condition querying the date against today().

If the logic relates to working-days they might be created at first within another flag-field which is afterwards accumulated and to max() aggregated and re-joined and in the next step a querying like above shown of date against max-date will return the MonthendFlag.

Should it relate to existing records within the facts you will need an aggregation logic like above suggested from @Kushal_Chawda whereby I wouldn't tend to join them back else applying it within a mapping to be able to set a zero as default value for the non-matching records.

In each case I suggest to do the work within the script by creating appropriate flag-fields and not in UI by applying it within complex set analysis conditions and/or further aggr() constructs if various dimensions needs to be considered.

Rocky6
Creator
Creator
Author

@marcus_sommer 

Month_Year sum({< MonthendFlag = {1}>} [Net Premium]) Expected Results
April2023 0 current date value as 50
March2023 250 250
Feb2023 400 300 as my last date will be 27 feb
Jan2023 0 300 as my last date value on 29th

 

marcus_sommer

It's not an answer to the question on which kind of date the logic relates to?

Rocky6
Creator
Creator
Author

This i have defined in editor. 

if(LAST_UPDATED_DATE = floor(monthend(LAST_UPDATED_DATE)), 1, 0) as MonthendFlag,

Last_Updated_Date is the field name.