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

Subtract Date - Problem with selection

Goodmorning to everyone,

I'm here with a problem without a solution in the community (at least, I didn't find a solution!).

I have a fact table that contain all the operation about a document. The fact is like

Id_documentId_operationDateMonth
xxxxyyyy131/10/2017October
xxxxyyyy201/11/2017November
eeeeffff107/11/2017November
eeeeffff209/11/2017November

I have to calculate the mean time between the operation 1 and 2.


=sum(aggr(sum({<Id_operation={'2'}>} Data)-sum({<Id_operation={'1'}>} Data),Id_document))/count({<DISTINCT Id_document)

For this example, the mean value is 1.5 days.

If i select one month (for example november), the value isn't correct (01/11/2017).

How can i consider only the document with all the operation in the month "November"?

Alternatively, how can i consider also the record with month "October" that have an operation in "November"?

I have to add two more columns (MonthID1 and MonthID2) and move the selection on that field?

Thanks in advice,

Best Regards from Italy!

Paolo

2 Replies
Colin-Albert

Are the dates loaded as text or are they correctly loaded as dual() fields?

I ask this because there are spaces in front of the Date & Month for 07/11/2017 in the data you posted.

Perhaps these posts will help you get the dates loaded correctly.

Why don’t my dates work?

Get the Dates Right

Also it may help you identify the issue if you add test expresions to your table for

sum({<Id_operation={'1'}>} Data) , sum({<Id_operation={'2'}>} Data) and count({<DISTINCT Id_document) so you can check those values are correct.

Anonymous
Not applicable
Author

The dates are loaded correctly as Date, here i posted only a few example wrote for example.

The problem is about Selection. When any Date and any Month aren't selected, the value is correct.

When one month is selected, the value isn't correct.

As you can see (using the example I posted), if i select "November" i have :

(09/11/2017 +01/11/2017 - 07/11/2017) / 2 = ??