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: 
Not applicable

Doubt with sum from today() to quarter

Hi everybody

I have to make a quarterly average.

I have 4 quarters. I did this with

CEIL(Num(Month(FECHA))/3)&'Q'AS QUARTER

Now with this i have Q1,Q2,Q3,Q4.

Ok i have to calculate the sum(money) from today() to the start of the quarter.

I mean, for example, we are in 25/02/2015. The start of the quarter is in 01/01/2015. Then i have to calculate 25/02/2015 - 01/01/2015 = 56 days

But if for example we'd be in 02/04/2015 it'd be 02/04/2015 - 01/04/2015 = 1 day

How i do this?

Thank you!

Greetings

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

This should work:

sum(if(InQuarterToDate(Date, today(),0), money))

/

count(distinct if(InQuarterToDate(Date, today(),0), Date))

View solution in original post

8 Replies
JonnyPoole
Former Employee
Former Employee

This would work to sum up 'Amount' where 'Date' is between today and the quarter start.

= sum(  {<Date={">=$(=QuarterStart(Today()))<=$(=Today())"}>}  [Amount])

Anonymous
Not applicable
Author

There is a function InQuarterToDate() just for your case:

sum(if(InQuarterToDate(Date, today(),0), money))

Not applicable
Author

Thank you! Now i have another doubt. I have to do the avg of this i mean the money between that two dates divided by the number of days

how i do this?

thank you!!!

Not applicable
Author

Thank you!

This function is working great


Now i have another doubt. I have to do the avg of this i mean the money between that two dates divided by the number of days

how i do this?

JonnyPoole
Former Employee
Former Employee

You can do date arithmetic for that. you may or may not need floor() function.

ex

sum(  {<Date={">=$(=QuarterStart(Today()))<=$(=Today())"}>}  [Amount])

/

(  floor(Today()) -  floor(QuarterStart(Today()))  + 1   )

Anonymous
Not applicable
Author

This should work:

sum(if(InQuarterToDate(Date, today(),0), money))

/

count(distinct if(InQuarterToDate(Date, today(),0), Date))

Not applicable
Author

Thank you

But i did this and it counts 24

count(distinct if(InQuarterToDate(FECHA, today(),0), FECHA))

It's counting from today to the start of the month

Greetings!

Anonymous
Not applicable
Author

Maybe you don't have FECHA every day(?)  Try the option from Jonathan (I simplified a little):

sum(if(InQuarterToDate(Date, today(),0), money))

/

(Today()-QuarterStart(Today())+1)