Forum Discussion
SQL Server Datatype -> Power Query Fixed decimal number ($)
- Anonymous4 years ago
Hi BA_Pete ,
It appears that the Value.NativeQuery does not work as I expected.
Created and populated a small test table.
CREATE TABLE [ref].[TestTable](
[MoneyDEF] [MONEY] NOT NULL,
[SmallMoneyDef] [SMALLMONEY] NOT NULL,
[DecimalDef] [DECIMAL](19, 4) NOT NULL,
[NumericDef] [NUMERIC](19, 4) NOT NULL,
[FloatDef] [FLOAT] NOT NULL
) ON [PRIMARY]
The following M gives the desired results in that the MONEY/SMALLMONEY columns are imported FIXED DECIMAL the others as FLOAT
let
Source = Sql.Database("myServer", "myDatabase"),
ref_TestTable = Source{[Schema="ref",Item="TestTable"]}[Data]
in
ref_TestTable
I have been using Value.NativeQuery, which for some reason - as yet to be determined - does not import the MONEY/SMALLMONEY as FIXED DECIMAL all columns are FLOAT
let
Source = Sql.Databases(Server),
db = Source{[Name = Database]}[Data],
TestTable = Value.NativeQuery(
db,
"SELECT
[MoneyDEF],
[SmallMoneyDef],
[DecimalDef],
[NumericDef]
FROM [ref].[TestTable]",
null,
[EnableFolding = true]
)
in
TestTable
The first workaround is not to use Value.NativeQuery but this outcome is a little surprising to me.
Will try and look more into Value.NativeQuery.
Regards,
B
Hi Anonymous ,
The fact that converting to Currency.Type in PQ breaks folding tends to suggest that there isn't a direct equivalent that can pass from SQL to PQ.
Why do you want to do this in PQ anyway? I, personally, always see Currency/Fixed Decimal as formatting rather than data type changes and thus always make these changes in the front end.
Pete
- Anonymous4 years agoNot applicable
Hi Pete,
I agree - for the reason you gave - that it is possibly the case that there isn't a direct equivalent that can pass from SQL to PQ as currency datatype.
The datatype conversion needs to be done, because the rounding issues of Fixed Decimal are not acceptable to our users, so the Currency datatype is implemented.Regards,
B
- BA_Pete4 years ago
Super User
Hi Anonymous ,
If it's rounding of the values that's the problem, then you can use the Number.Round~ family of functions in Power Query. There's a few different types you can use, and each have different arguments you can use to get exactly the behaviour you need:
https://docs.microsoft.com/en-us/powerquery-m/number-round
I believe all of these functions will fold to SQL Server.
Pete
- Anonymous4 years agoNot applicable
Hi BA_Pete,
I think that this article explains the requirement for the Fixed Decimal rather than Floating Point better than I can.
Choosing Numeric Data Types in DAX - SQLBI
Regards,
B