# Qlik Sense App Development

Announcements
cancel
Showing results for
Did you mean:
Partner

## Cost comparison to LY

I have an existing Sales app and I would like to compare the cost prices of the items I sold this year to the same items sold the previous year.

Currently I have this expressions to calculate this ytd values:

SUM({<[Sales_Fin_Year]=,Sales_Month=,Date = {">=\$(=YearStart(Today(),0))<=\$(=AddYears(Today(),0))"} >} [Unit Cost])

and SUM({<[Sales_Fin_Year]=,Sales_Month=,Date = {">=\$(=YearStart(Today(),-1))<=\$(=AddYears(Today(),-1))"} >} [Unit Cost]) to calculate previous ytd.

I would like to only show the costs for item sold this years as well as last year and exclude items that were sold in only one of the two years.

I am not entirely sure if this can be done but would appreciate any help in this regard.

Thanking you.

1 Solution

Accepted Solutions
Specialist

Hi, John, try to multiply by the condition of the fact of sales in a related year

SUM({<[Sales_Fin_Year]=,Sales_Month=,Date = {">=\$(=YearStart(Today(),0))<=\$(=AddYears(Today(),0))"} >} [Unit Cost])  * If( Aggr(SUM({<[Sales_Fin_Year]=,Sales_Month=,Date = {">=\$(=YearStart(Today(),-1))<=\$(=AddYears(Today(),-1))"} >} [Unit Cost]) , [You Item Field]) > 0, 1)

second expr

SUM({<[Sales_Fin_Year]=,Sales_Month=,Date = {">=\$(=YearStart(Today(),-1))<=\$(=AddYears(Today(),-1))"} >} [Unit Cost]) * If( Aggr(SUM({<[Sales_Fin_Year]=,Sales_Month=,Date = {">=\$(=YearStart(Today(),0))<=\$(=AddYears(Today(),0))"} >} [Unit Cost]), [You Item Field]) > 0, 1)

2 Replies
Specialist

Hi, John, try to multiply by the condition of the fact of sales in a related year