Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
EL_MAR
Contributor III
Contributor III

Calculating YTD in Qlick View

I want to calculate the YTD for every given year, as seen in the table.

EL_MAR_0-1717493464654.png

I have the following formula for the max year. Does anybody have an idea how to adapt the formula so the YTD is calculated individualy for every single year. If possible I would like a formel that can be used for the whole table instead of having a formula for each year

=Num((Sum({<Valuationdate={"$(vYearEnd)"}>}[Adjusted NAV])-Sum({<Valuationdate={"$(vYearStart)"}>}[Adjusted NAV]))/Sum({<Valuationdate={"$(vYearStart)"}>}[Adjusted NAV]),'##,##%')

Labels (2)
1 Solution

Accepted Solutions
EL_MAR
Contributor III
Contributor III
Author

I created a quick fix which is working for me. The thing that was weirding out the table was the dimension, because trough the dimension Year that I had and the years in the formula their interacted with oneanother. To eliminate that I left out the dimension and created the formula for YTD:

=Num(
(Sum({<Valuationdate = {"$(=Date(Max({<Year={2024}>} Valuationdate)))"}>} [Adjusted NAV])
- Sum({<Valuationdate = {"$(=Date(Min({<Year={2024}>} Valuationdate)))"}>} [Adjusted NAV]))
/
Sum({<Valuationdate = {"$(=Date(Min({<Year={2024}>} Valuationdate)))"}>} [Adjusted NAV])
, '##,##%')

In the tab Presentation I have the title 2024, as written in the example. I did that for each year and got the following table:

EL_MAR_0-1727333851544.png

The next Problem was to have the Ultimo Date (last working date of the month) to calculate the correct YTD. I did that in the script that filtered for Ultimo 1, so if it is Ultimo it produces a 1. With that I implemented a filter, so that just the ultimo dates are calculated. If not activated it calculates the YTD from the Min Date to the overall Max Date.

View solution in original post

16 Replies
TauseefKhan
Creator III
Creator III

Hi @EL_MAR,

Check with this:

YTD:
Num((
Sum({<Year(Valuationdate) = $::Year(Valuationdate), Valuationdate={"<=$(=Max({<Year(Valuationdate) = $::Year(Valuationdate)>} Valuationdate))"}>} [Adjusted NAV]) -
Sum({<Year(Valuationdate) = $::Year(Valuationdate), Valuationdate = {"$(=Date(YearStart(Max(Valuationdate)), 'YYYY-MM-DD'))"}>} [Adjusted NAV])
) / Sum({<Year(Valuationdate) = $::Year(Valuationdate), Valuationdate = {"$(=Date(YearStart(Max(Valuationdate)), 'YYYY-MM-DD'))"}>} [Adjusted NAV]),
'##,##%')

******Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.******** 

EL_MAR
Contributor III
Contributor III
Author

Hi,

the function is not working. It says there is an error...

TauseefKhan
Creator III
Creator III

Check this:

Num(
(Sum({<Year(Valuationdate) = $::Year,
Valuationdate = {"<=$(=Max({<Year(Valuationdate) = $::Year>} Valuationdate))"}>}
[Adjusted NAV])
- Sum({<Year(Valuationdate) = $::Year,
Valuationdate = {"=$(=YearStart(Max({<Year(Valuationdate) = $::Year>} Valuationdate)))"}>}
[Adjusted NAV]))
/ Sum({<Year(Valuationdate) = $::Year,
Valuationdate = {"=$(=YearStart(Max({<Year(Valuationdate) = $::Year>} Valuationdate)))"}>}
[Adjusted NAV]),
'##,##%')

EL_MAR
Contributor III
Contributor III
Author

EL_MAR_0-1718287218857.png

It still indicates that there is an errror. I copy and past it straight as it was written

 

lennart_mo
Creator
Creator

You could try defining the variables with dynamic values rather than one static value.

The value of vYearEnd could be defined as YearEnd(Valuationdate) i.e., so you can use your initial formula with this variable, except maybe you'll need to add an '=' in the $ expression to resolve the string.

=Num((Sum({<Valuationdate={"$(=vYearEnd)"}>}[Adjusted NAV])
-Sum({<Valuationdate={"$(=vYearStart)"}>}[Adjusted NAV]))
/Sum({<Valuationdate={"$(=vYearStart)"}>}[Adjusted NAV]),'##,##%')

 

EL_MAR
Contributor III
Contributor III
Author

If I use the vYearEnd the formula is calculating for just the current year. 

Maybe my script helps to find a solution...

 

EL_MAR_0-1718353153805.png

 

EL_MAR
Contributor III
Contributor III
Author

YTD formula:


=Num((Sum({<Valuationdate={"$(vYearEnd)"}>}[Adjusted NAV])-Sum({<Valuationdate={"$(vYearStart)"}>}[Adjusted NAV]))/Sum({<Valuationdate={"$(vYearStart)"}>}[Adjusted NAV]),'##,##%')

I wanted to add the additional formulas that are in the main formula:

vYearStart: =Monthend(YearStart(Max(Valuationdate)))

vYearEnd: =Max(Valuationdate)

marcus_sommer

Such matching shouldn't be done within the UI else within the data-model in the calendar and this is there quite easy, for example:

if(daynumberofyear(Date) < daynumberofyear(today()), 1, 0) as YTD,
daynumberofyear(Date) as DayNumber

and then an expression might be look like:

sum({< YTD = {1}>} Value)

juliano_arruda
Partner - Contributor III
Partner - Contributor III

@EL_MAR , criando uma tabela simples e usando a dimensão de ANO, cria a medida RangeSum(Above(Sum([Valor]), 0, RowNo())).

Acredito que seja suficiente para trazer o acumulado ano a ano. Seria isso?