Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

delta error with null or zero values

Good morning,

you can help me solve the following problem ?

In a table I display the delta between two quantities, in current and previus year, for example:

Sheet1 - year 2015

MonthProduct1Product2

Jan

100150
Feb200100
Mar5050

Sheet2 - Year 2016

YearMonthProduct1Product2
2016Jan150200
2016Feb100120
2016Mar--

by calculating the delta I get the following result


Difference between years 2016/2015:

MonthProduct1Product2
Jan50,00%

33,33%

Feb-50,00%20%
Mar-100%-100%


The expression used in the measurement is:

(sum(if (InYear (Anno, Today(), 0), [Product1]))-sum(if (InYear (Anno, Today(), -1), [Product1])))

/sum(if (InYear (Anno, Today(), -1),[Product1]))


How can it not be calculated when the product contains no value in that month ?

So as not to show -100 %?


Thanks for the support

1 Solution

Accepted Solutions
swuehl
MVP
MVP

There might be different solutions possible depending on your data model etc.

This should return zero for the months with missing current year data:

=Count(if (InYear (Anno, Today(), 0), [Product1]))

So you can use this count in an if() statement to check your condition:

=If( Count(if (InYear (Anno, Today(), 0), [Product1])),

(sum(if (InYear (Anno, Today(), 0), [Product1]))-sum(if (InYear (Anno, Today(), -1), [Product1])))

/sum(if (InYear (Anno, Today(), -1),[Product1]))

,Null()

)

View solution in original post

7 Replies
maxgro
MVP
MVP

with this small test script

P:

load

  date(makedate(2015) + floor(rand()*730)) as Date,

  ceil(rand()*100) as Product1,

  ceil(rand()*100) as Product2

AutoGenerate 1000;

Left Join (P)

load Distinct Date, Month(Date) as Month, Year(Date) as Year

Resident P;

I think you can use a chart with this expression for Product1

(sum({$ <Year={$(=Year(Today()))}>} Product1) - sum({$ <Year={$(=Year(Today())-1)}>} Product1))

/

(sum({$ <Year={$(=Year(Today())-1)}>} Product1))

1.png

Not applicable
Author

Thanks for the reply .

I tried to apply your formula, but nothing has changed . In the months of 2016 that have no data displays -100 %.


I do not know if it's possible, but I should put an IF product1 not isnull ( ) performs the calculations otherwise put 0 . It's possible?

swuehl
MVP
MVP

There might be different solutions possible depending on your data model etc.

This should return zero for the months with missing current year data:

=Count(if (InYear (Anno, Today(), 0), [Product1]))

So you can use this count in an if() statement to check your condition:

=If( Count(if (InYear (Anno, Today(), 0), [Product1])),

(sum(if (InYear (Anno, Today(), 0), [Product1]))-sum(if (InYear (Anno, Today(), -1), [Product1])))

/sum(if (InYear (Anno, Today(), -1),[Product1]))

,Null()

)

Not applicable
Author

Perfect work! Great!!!

oknotsen
Master III
Master III

If your question is answered, please flag the Correct Answer and optionally Helpful Answers.

If not, please make clear what part of your question still needs answering .

May you live in interesting times!
Not applicable
Author

Ok sorry!

oknotsen
Master III
Master III

No worries . Better clear that you have your answer instead of assuming you have the answer but are still looking for one!

As you did not add a new question, I assumed you mend to mark Stefan's reply as the Correct Answer. I made the change as this "closes" the topic.

May you live in interesting times!