# App Development

Announcements
Qlik Insider: SaaS capabilities for Data Integration and Analytics, May 25th! Register Now
cancel
Showing results for
Did you mean:
Creator

## Calculate day difference and possible duplicate rows

Hi Experts.

I am trying to calculate the difference between two dates (a date and a dateTimeStamp).

-When I sum the dimension, it is not doing as I am specting: Days = Sum(DIAS_INSTALACION)

The script editor:

```Ventas:
First 52000
PEDIDO_ID,
Date(Floor(TimeStamp(FECHA_INSTALACION,'DD/MM/YYYY hh:mm:ss')), 'DD/MM/YYYY') as FECHA_INSTALACION,
FECHA_CITA

FROM [lib://Datos/VENTAS_TBL.qvd]
(qvd);

left join
PEDIDO_ID,
Num(FECHA_CITA-FECHA_INSTALACION) as DIAS_INSTALACION
Resident Ventas;```

Am I missing something?

Labels (2)

• ### Script

1 Solution

Accepted Solutions
MVP

What happens if you use measure SUM(DIAS_INSTALACION) instead of the dimension DIAS_INSTALACIONin your chart?

I notice you are joining the data back into your Ventas table, if you hav duplicate PEDIDO_ID then your join will create duplicate rows. You could try this approach instead.

```Ventas:
LOAD   PEDIDO_ID,   FECHA_CITA,    FECHA_INSTALACION,  Num(FECHA_CITA-FECHA_INSTALACION) as DIAS_INSTALACION ;
PEDIDO_ID,   FECHA_CITA,
dayname(TimeStamp(FECHA_INSTALACION,'DD/MM/YYYY hh:mm:ss')) as FECHA_INSTALACION
FROM    [lib://Datos/VENTAS_TBL.qvd] (qvd);

```
Plees ekskuse my Swenglish and or Norweglish spelling misstakes
6 Replies
Specialist II

Hi,

Will you be able to share masked data and or sample QVF file?

MVP

What happens if you use measure SUM(DIAS_INSTALACION) instead of the dimension DIAS_INSTALACIONin your chart?

I notice you are joining the data back into your Ventas table, if you hav duplicate PEDIDO_ID then your join will create duplicate rows. You could try this approach instead.

```Ventas:
LOAD   PEDIDO_ID,   FECHA_CITA,    FECHA_INSTALACION,  Num(FECHA_CITA-FECHA_INSTALACION) as DIAS_INSTALACION ;
PEDIDO_ID,   FECHA_CITA,
dayname(TimeStamp(FECHA_INSTALACION,'DD/MM/YYYY hh:mm:ss')) as FECHA_INSTALACION
FROM    [lib://Datos/VENTAS_TBL.qvd] (qvd);

```
Plees ekskuse my Swenglish and or Norweglish spelling misstakes
Creator
Author

I'm attaching an example.

MVP

As you see in the screenshot below, you have duplicate PEDITO_ID, which leads to the sum(DIAS_INSTALATCION) will be wrong, when joining a table without a unique primary key you could get duplicate rows.  I think you should consider my preceding load solution in my earlier answer.

Plees ekskuse my Swenglish and or Norweglish spelling misstakes
Creator
Author
Thanks Vegar. The only thing is that it takes more time.
MVP
If you still want to use join then you need to find or create an unique identifier to the tables so you are not joining duplicates. If the data does not provide you could manually as to who() to your master Ventas table.
Plees ekskuse my Swenglish and or Norweglish spelling misstakes