Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
I have been conducting a research for quite a while now about the difference between a set analysis and an if statement, and yet to make any kind of conclusion.
To further understand my case, consider the following scenario:
The statements used are the following:
Each of the above statements returns a different value. Why? When should I use each of those statements ?
How does a set analysis statement work exactly ?
A sample of my data model has been attached for further clarifications.
Would appreciate any opinion on the matter,
Rawad @
All other conditions being equal, the two examples should return the same result. The difference in your examples resides mainly in efficiency and speed.In addition to that, set analysis is way more powerful for advanced aggregation than any IF THEN ELSE construct.
This is what happens when the two expressions are evaluated:
Best,
Peter
Hi Peter,
If you check the attached qvw file, you can see that the two expressions do not return the same result.
Any explanation as to why ?
Thank you,
Rawad
That's not too difficult to find out. The IF() logic traces associations, while set analysis just reduces/expands the data set and goes on with the result in table Transactions.
For example, recreate your two tables but this time add a RowNo() column. Now for every internal table, create a table box that includes the RowNo column and each individual field. Select %RandomId = 0156510500311000. That's one of the Ids that is responsible for the difference between the two Sum() result.
Both tables have a lot of superfluous rows. The Transactions table contains 8 rows, of whuch only 4 contain an actual amount. The OTP table even has 6 identical rows for this RandomId. If you replay the IF approach, associative logic will combine 6 OTP records with 8 Transactions rows. But since three of the four amounts annihilate each other, you'll get 6 times a value of 0,89 = 5,34.
The set analysis approach just sums the 8 rows in Transactions and produces 0,89. IMHO the set analysis result is correct.
Eliminate all redundant rows, and the expressions will produce the same result.
Peter