Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Lucius_Artorius_Castus

How to show bar chart with sum of only latest month for each year

Hi, So I want to sum only latest month for each year like below

Lucius_Artorius_Castus_0-1707396117559.png

Right now as you can see i am able to generate this chart till 2023 with this expression SUM({<[CREATED_DATE-Year-Month.autoCalendar.MonthRelNo] = {"-10"}>} [FA_QTY_FUNC] * [AVERAGE_PRICE]) / 1000)
because it has latest month which is 12, but for 2024 latest month is Feb so I want to only sum for feb data
Please Let me know how should I achieve this.

Thanks.

Labels (1)
  • SaaS

1 Solution

Accepted Solutions
Lucius_Artorius_Castus
Author

I solved this by creating new two columns Latest_YM where I am storing latest month of specific year and second is YMFlag field I have created where I am subtracting both date fields if it is 0 then I put flag 0 otherwise 1
if (interval([Year-Month]-[YEAR_MONTH_CALC], 'd') = 0, 0 , 1)

Lucius_Artorius_Castus_0-1707483781335.png

And in expression I have filtered with SUM({<[YMFlag]={'0'}>} [FA_QTY_FUNC] * [AVERAGE_PRICE]) / 1000) 

Lucius_Artorius_Castus_1-1707484140092.png

 

 Thanks everyone for helping me. If there is better solution Let me know but this work for me for now.

 

View solution in original post

11 Replies
Anil_Babu_Samineni

@Lucius_Artorius_Castus Perhaps this way?

SUM({<[CREATED_DATE-Year-Month.autoCalendar.MonthRelNo] = {"-10"}, Monthfield={"$(=Max(Monthfield))"}>} [FA_QTY_FUNC] * [AVERAGE_PRICE]) / 1000)

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
qv_testing
Specialist II
Specialist II

PFA,

Lucius_Artorius_Castus
Author

Thanks for Reply,
It didn't work, Because I don't have monthfield I am using CREATED_DATE-Year-Month which is YYYY-MM date format(2024-02), Sorry I should have told you before, Please let me know what changes I should make with this format.

Lucius_Artorius_Castus
Author

Thanks for reply,

let me try it.

Lucius_Artorius_Castus
Author

Ok I tried it, it is only showing till 2023 as you can see in above chart, it is not generating the bar for 2024 where we want data of Feb which is max in 2024.
Below is log showing when I write expression

Lucius_Artorius_Castus_0-1707460217324.png

 

Lucius_Artorius_Castus
Author

@qv_testing @Anil_Babu_Samineni Just to be clear what I want is this

Lucius_Artorius_Castus_0-1707462742749.png

which I have achieved with this formula SUM({<[CREATED_DATE-Year-Month.autoCalendar.MonthRelNo] = {"-10"}>} [FA_QTY_FUNC] * [AVERAGE_PRICE]) / 1000)
somehow it worked, But when I loaded the new data it didn't work.
in this 2021 is showing data for Dec,
2022-Dec, 2023-Dec and 2024-JAN Because at that time I had data till Jan

Thanks.

Anil_Babu_Samineni

@Lucius_Artorius_Castus From my expression given earlier can still deserve the same If you can change the Field name (Maybe in few case, you might needed the date formats around to get match).

We appreciate sharing sample data set and QVF together to have a look and we may suggest faster. 

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Lucius_Artorius_Castus
Author

Sure,

Please find below attachment

qv_testing
Specialist II
Specialist II

Try with this..

Create one field in calendar like
Year(Date)*100+num(Month(date)) as YearMonth   //this will create a number like 202401...so on

Load Year as TestYear,
         Max(YearMonth) as YearMonth,   // Year wise max year month
        '1' as MaxYearMonthFlag
resident Calendar
group by Year;

in expression you can use MaxYearMonthFlag={1}