Hi
I am using Microsoft Dynamics NAV 2013 , SQL server 2014 , Tableau Desktop
I have created a new table which contains data from the Excise Rate, Location , Item and Item Unit of Measure tables in order to calculate Transfer Excise. Transfer Excise is Tax that we pay when our wine gets transported from one Warehouse to another. I did a Left Join to the Value Entry table which contains all item related transactions as I need the Invoice Quantity column to calculate Transfer Excise. This is how I calculate Transfer Excise: (Invoiced Quantity / Litre Conversion Factor * Unit Rate) = Transfer Excise. With this approach I did get the desired result , see the SQL script to get the Transfer Excise
SELECT DISTINCT b.[Entry No_] ,
a.[Starting Date],
b.[Posting Date],
b.[Item No_],
b.[Invoiced Quantity],
b.[Sales Amount (Actual)],
a.[Litre Conversion Factor],
a.[Unit Rate] ,
b.[Location Code],
a.[Excise Location],
a.[Excise Type Code],
a.[Unit Of Measure Code]
FROM [Spier Live$Value Entry] b
LEFT JOIN [Transfer Excise Tbl] a
ON a.[No_] = b.[Item No_]
AND b.[Location Code] = a.[Location Code]
AND DateDiff(y,b.[Posting Date],a.[Starting Date]) > -365
AND DateDiff(y,b.[Posting Date],a.[Starting Date]) < 0
WHERE b.[Posting Date] > '2013-02-26'
AND b.[Gen_ Bus_ Posting Group] IN ('LOCA','EXSA')
AND b.[Invoiced Quantity] <>0
GROUP BY b.[Entry No_] ,a.[Starting Date], b.[Posting Date], b.[Item No_], b.[Invoiced Quantity],
b.[Sales Amount (Actual)], a.[Litre Conversion Factor], a.[Unit Rate] ,
b.[Location Code], a.[Excise Location], a.[Excise Type Code], a.[Unit Of Measure Code]
With all this done , the sales amount (Actual) value changes which should not be the case. Someone told me that it might be the Left Join causing the Sales Amount(Actual) to change. I cannot change the script because then the Transfer Excise Value will be incorrect or is there another or better way of writing this query so that the sales amount (Actual) and Transfer Excise values will remain the same. Oh the reason for the way i wrote the query is because i want to get the Unit Rate for each item transaction.
0
Answers
Although the SQL statement is odd, it could not cause a wrong representation of Sales Amount (Actual).
Perhaps Tableau does something to the data before display?
You could test your SQL in SQL Server Management Studio.
good luck.
My final thought, could the filter [WHERE b.[Posting Date] > '2013-02-26'
AND b.[Gen_ Bus_ Posting Group] IN ('LOCA','EXSA')
AND b.[Invoiced Quantity] <>0]
be different in your other Sales Amount(Actual) report/query/cube?
I am sorry you cannot test in SQL server management studio. That would make things a lot easier.
Good luck.
AND b.[Gen_ Bus_ Posting Group] IN ('LOCA','EXSA')
AND b.[Invoiced Quantity] <>0] Filters was done to get the correct data from my Transfer Excise table to calculate Transfer Excise. If the filters is the problem what better way is there so that the Left Join to the Transfer Excise Tbl and the filters does not affect the Sales Amount (Actual) value
It seems like you are sometimes jumping to conclusions.
The filter is 100% on table b, the value entry.
Good luck.
If any of them are, they are being excluded.
If all amounts are >0, then you should get less than when you just sum across the specified dates.
If amounts can be less than zero, then you may get more or less or equal to the amount you get when you just sum across the dates.
In other words, unless the field list you are using to select from represents a primary key, you are probably leaving out some of the records due to the distinct clause.
have you tried this statement without the distinct clause?
Michael
This means, the mapping from a to b is not 1:1 which it probably should be.
If the mapping is not 1:1, you cannot sum Sales Amount (Actual) in the result and expect it to be the correct Sales Amount (Actual).
If it shold be 1:1, check the join condition (it's likely the values in a.[Starting Date] which cause you trouble, then).