TRUNC function DAX

TRUNC function is a Power BI math and trig function in DAX, which truncates a number to an integer by removing the decimal, or fractional part of the number.



TRUNC function does not round the number down to the nearest integer based on the value of the fractional part of the number.

TRUNC and INT function are similar as both return integers but the only difference is that TRUNC function removes the fractional part of the number while INT rounds numbers down to the nearest integer based on the value of the fractional part of the number.

SYNTAX
TRUNC(number,num_digits)
number is the number you want to truncate.
num_digits is a number specifying the precision of the truncation. By default is 0, if not specified

Lets take a look at TRUNC function in Power BI.

Here we have a sample dataset Numbers as shown below.

Copy sample data :
Value
1234.786
123456.78
-1235.89
-1234565.7967
134674.78
6347.5890
-67.79

Lets create a calculated column which will remove or truncates a decimal part from numbers in value column and return an integer number.

Trunc_Value = TRUNC(Numbers[Value])

You can see, it truncates a number to an integer by removing the decimal part.

Specifying the precision of the truncation 

You can also specify the precision of the truncation, means you can also truncate the decimal part of number at specified number of places.



Lets truncates the decimal part of number to the 1 place of decimal. For this, you need to specify a second argument num_digits value as 1 to TRUNC function.

Lets create one more calculated column in dataset as shown below.

Trunc_Value_Decimal_1_Place = TRUNC(Numbers[Value], 1)

You can see, it truncates a number to the 1 place of decimal.

Also Read..

SUM

SUMX

DIVIDE



SQL Basics TutorialSQL Advance TutorialSSRSInterview Q & A
SQL Create tableSQL Server Stored ProcedureCreate a New SSRS Project List Of SQL Server basics to Advance Level Interview Q & A
SQL ALTER TABLESQL Server MergeCreate a Shared Data Source in SSRSSQL Server Question & Answer Quiz
SQL DropSQL Server PivotCreate a SSRS Tabular Report / Detail Report
..... More.... More....More
Power BI TutorialAzure TutorialPython TutorialSQL Server Tips & Tricks
Download and Install Power BI DesktopCreate an Azure storage accountLearn Python & ML Step by stepEnable Dark theme in SQL Server Management studio
Connect Power BI to SQL ServerUpload files to Azure storage containerSQL Server Template Explorer
Create Report ToolTip Pages in Power BICreate Azure SQL Database ServerDisplaying line numbers in Query Editor Window
....More....More....More

 306 total views,  1 views today

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.