Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
james_butler
Contributor III
Contributor III

Using the Max function in an expression

Hi

I'm wanting to sum the value in stock for the last day in the week (to get a closing balance). I thought max would help but i haven't had any luck with the below expression.... Any ideas why?

sum(

{$<

            Year=,

            Week=,

            Date = {$(=max(Date))},

            IsTrackedPart = {1}

>}

[Inventory Quantity in Stock]

)

Thanks

James

6 Replies
JonnyPoole
Former Employee
Former Employee

Is the last day of the week always say Saturday ? 

=Date(Date,'WWWW')    will return full days like  'Saturday', 'Friday' etc...

james_butler
Contributor III
Contributor III
Author

Correct, Saturday is always the last day in the week.

stigchel
Partner - Master
Partner - Master

Your Date field is probably a real date format field, in that case the right hand side of your compariosn in the set analysis is expecting a text format, so you will need quotation marks around the $(=) and you will need to format the text to match the format of your date field. Use the date function for that.

Date = {'$(=Date(max(Date),'DD-MM-YYYY')'}


Replace the 'DD-MM-YYYY' with your own format

rustyfishbones
Master II
Master II

Hi James,

Try adding Weekday in your Calendar and then change the Expression to.

sum(

{$<

            Year=,

            Week=,

           WeekDay = {'Sat'},

            IsTrackedPart = {1}

>}

[Inventory Quantity in Stock]

)

JonnyPoole
Former Employee
Former Employee

Try this as your expression

if(  Date(Date,'WWWW') = 'Saturday' and IsTrackedPart = 1, sum(   [Inventory Quantity in Stock] ) ) 

or this:

sum ( if(  Date(Date,'WWWW') = 'Saturday' and IsTrackedPart = 1,  [Inventory Quantity in Stock] ) ) 

and ensure suppress zero values is enabled on the presentation tab of the chart properties.

james_butler
Contributor III
Contributor III
Author

The field Date is in numerical format.