Data types

For structured data sources, such as SQL Server, the source column data types will determine the data types applied in Power BI. For example, a money data type in SQL Server will result in a Fixed Decimal Number data type in Power BI. Likewise, the integer data types in SQL Server will result in a Whole Number data type and the numeric and decimal data types in SQL Server will result in Decimal Number data types in Power BI. 

When an M query is loaded to the data model in a Power BI dataset, a Fixed Decimal Number data type is the equivalent of a (19,4) numeric or decimal data type in SQL Server. With four digits to the right of the decimal place, the use of the Fixed Decimal Number data type avoids rounding errors. The Decimal Number data type is equivalent to a floating point or approximate data type with a limit of 15 significant digits. Given the potential for rounding errors with Decimal Number data types and the performance advantage of Fixed Decimal Number data types, if four digits of precision is sufficient, the Fixed Decimal Number data type is recommended to store numbers with fractional components. All integer or whole number numeric columns should be stored as Whole Number types in Power BI.

Numeric columns in M queries can be set to Whole Number, Fixed Decimal Number, and Decimal Number data types via the following expressions, respectively—Int64.Type, Currency.Type, and type number. The Table.TransformColumnTypes() function is used in the following M query example to convert the data types of the Discount Amount, Sales Amount, and Extended Amount columns:

let
Source = AdWorksSQLServer,
Sales = Source{[Schema = "BI", Item = "vFact_InternetSales"]}[Data],
TypeChanges = Table.TransformColumnTypes(Sales,
{
{"Discount Amount", Int64.Type}, // Whole Number
{"Sales Amount", Currency.Type}, // Fixed Decimal Number
{"Extended Amount", type number} // Decimal Number
})
in
TypeChanges
As M is a case-sensitive language, the data type expressions must be entered in the exact case, such as type number rather than Type Number. Note that single-line and multi-line comments can be included in M queries. See the M query examples section later in this chapter for additional details.

Given the impact on performance and the potential for rounding errors, it's important to check the numeric data types defined for each column of large fact tables. Additional details on data types are included in Chapter 3, Designing Import and DirectQuery Data Models.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.4