Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Help, difference between two (2) data sets
kidtorres
<p>Hi all, I need to calculate with a data item the difference between two columns of two different data sets.</p><p>Here is the example:</p><p>1st Query:</p><p>SELECT ID_MONEDA, SUM(I_COBRO)
FROM FAC_COBROS
WHERE O_EMPRESA = NVL(:p_o_empresa, O_EMPRESA)
AND F_LIQUIDACION = NVL(:p_f_liquidacion, F_LIQUIDACION)
AND N_LIQUIDACION = NVL(:p_n_liquidacion, N_LIQUIDACION)
GROUP BY ID_MONEDA</p><p> </p><p>2nd Query:</p><p>SELECT ID_MONEDA, SUM(I_PAGO)
FROM FAP_PAGOS
WHERE O_EMPRESA = NVL(:p_o_empresa, O_EMPRESA)
AND F_LIQUIDACION = NVL(:p_f_liquidacion, F_LIQUIDACION)
AND N_LIQUIDACION = NVL(:p_n_liquidacion, N_LIQUIDACION)
GROUP BY ID_MONEDA</p><p> </p><p>WhaT I need is to put in a table the result form (SUM(I_PAGO) - SUM(I_COBRO))</p><p>Each query can return 1, 2 or 3 columns.</p><p>Thank you very much!!!</p>
Find more posts tagged with
Comments
micajblock
<p>Have you tried joined data set?</p>
kidtorres
<blockquote class="ipsBlockquote" data-author="mblock" data-cid="121675" data-time="1383229829"><div><p>Have you tried joined data set?</p></div></blockquote><p>I create a Joint Data set with those two querys wiht inner join, and then in the joint query I create a computed column thay was row["SUM(I_PAGO"] - row["SUM(I_COBRO)"] but nothing happened, did I do something wrong??</p>
bgbaird
<p>There are lots of methods to do this, depending on where you want the work done. </p><p> </p><p>If you do the join in data without computing does it work? If so, you could just use the dataset to get all the results, and do the math in the report.</p><p> </p><p>Brian</p>
Hans_vd
<p>Are [color=rgb(0,0,0);font-family:helvetica, arial, sans-serif;]<strong>row["SUM(I_PAGO"]</strong> and <strong>row["SUM(I_COBRO)"]</strong> really the names of the data set fields?[/color]</p><p>[color=rgb(0,0,0);font-family:helvetica, arial, sans-serif;]And if so, isn't there a ) missing in the first one?[/color]</p>
kidtorres
<blockquote class="ipsBlockquote" data-author="bgbaird" data-cid="121680" data-time="1383234861"><div><p>There are lots of methods to do this, depending on where you want the work done. </p><p> </p><p>If you do the join in data without computing does it work? If so, you could just use the dataset to get all the results, and do the math in the report.</p><p> </p><p>Brian</p></div></blockquote><p>Yes if do it wuthout computing works but it onle shows 1 column.. </p><p>The only way that it works is if I make a data set with the two querys with an Union All, but I dont know how to create a data item that can calculate the difference between the two rows..</p>
kidtorres
<blockquote class="ipsBlockquote" data-author="Hans_vd" data-cid="121683" data-time="1383236782"><div><p>Are [color=rgb(0,0,0);font-family:helvetica, arial, sans-serif;]<strong>row["SUM(I_PAGO"]</strong> and <strong>row["SUM(I_COBRO)"]</strong> really the names of the data set fields?[/color]</p><p>[color=rgb(0,0,0);font-family:helvetica, arial, sans-serif;]And if so, isn't there a ) missing in the first one?[/color]</p></div></blockquote><p>Yes, those are the real names, and the missing ) was a mistake that I made typing here jejeje sorry and thanks for the help..</p>
micajblock
<p>What do you mean 'nothing happened' when you do a Joined data set? What happens when you preview the data in the data set editor?</p>
Hans_vd
<p>And what happens if you give the sum fields an alias?</p>
kidtorres
<blockquote class="ipsBlockquote" data-author="mblock" data-cid="121687" data-time="1383239556"><div><p>What do you mean 'nothing happened' when you do a Joined data set? What happens when you preview the data in the data set editor?</p></div></blockquote><p>I meant that it didnt show the table, as if it doesn´t exist the joined data set that I created.</p><p> </p><p>The result would be:</p><p>1st query could return:</p><p>ID_MONEDA SUM(I_COBRO):</p><p>$ 17.000</p><p>U$S 20.000</p><p>£ 5.000</p><p> </p><p>2nd query could return:</p><p>ID_MONEDA SUM(I_PAGO):</p><p>$ 13.000</p><p>U$S 18.000</p><p>£ 1.000</p><p> </p><p>And what I need to display is the diference between the columns, I_COBRO and I_PAGO (I_COBRO - I_PAGO):</p><p>ID_MONEDA Difference:</p><p>$ 4.000</p><p>U$S 2.000</p><p>£ 4.000</p><p> </p><p>Thank you ALL!!!!!</p>
micajblock
<p>The fact that it did not show in the table might be a binding issue. What do you see when you click on 'Preview Results' when you edit the joined data set?</p>
kidtorres
<blockquote class="ipsBlockquote" data-author="mblock" data-cid="121696" data-time="1383245239"><div><p>The fact that it did not show in the table might be a binding issue. What do you see when you click on 'Preview Results' when you edit the joined data set?</p></div></blockquote><p>I can´t see anything because both querys depends on parameters, so in the preview results I can´t set them.</p><p>It´s something very easy to do in Oracle reports but here is very dificult, I dont know how to do it jaja</p>
micajblock
<blockquote class="ipsBlockquote" data-author="kidtorres" data-cid="121702" data-time="1383249398"><div><p>I can´t see anything because both querys depends on parameters, so in the preview results I can´t set them.</p><p> </p></div></blockquote><p> </p><p>You can set default values for the parameters and then you can preview the results.</p><p> </p><blockquote class="ipsBlockquote" data-author="kidtorres" data-cid="121702" data-time="1383249398"><div><p>It´s something very easy to do in Oracle reports but here is very difficult.</p></div></blockquote><p> </p><p>Not difficult, just different that what you are used to in Oracle reports. In the attached design I show 2 ways to so this. One using a joined data set (if done correctly you WILL get results). The other uses sub queries to perform the join on the database. Both work.</p><p> </p><blockquote class="ipsBlockquote" data-author="kidtorres" data-cid="121702" data-time="1383249398"><div><p>I dont know how to do it java</p></div></blockquote><p> </p><p>You do not need to know Java (as demonstrated in the examples). You can use JavaScript to store variables from the first query and use them in the second, but my examples are much easier (I did not write any code in my examples).</p>
kidtorres
<blockquote class="ipsBlockquote" data-author="mblock" data-cid="121706" data-time="1383253379"><div><p>You can set default values for the parameters and then you can preview the results.</p><p> </p><p> </p><p>Not difficult, just different that what you are used to in Oracle reports. In the attached design I show 2 ways to so this. One using a joined data set (if done correctly you WILL get results). The other uses sub queries to perform the join on the database. Both work.</p><p> </p><p> </p><p>You do not need to know Java (as demonstrated in the examples). You can use JavaScript to store variables from the first query and use them in the second, but my examples are much easier (I did not write any code in my examples).</p></div></blockquote><p> </p><p>Thank you very very much, I could use the example of the jonied data. I end up using a full outer join, because sometimes, one query could return 1 row, and the other query 2 rows, so your example helped me a lot.</p><p>THANK YOU again!!!</p><p>Best regards.</p>