0% found this document useful (0 votes)
11 views

New DAX

Uploaded by

Farshad Asghari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

New DAX

Uploaded by

Farshad Asghari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

www.DataToInsight.

ir
‫امیر ایـمن پور‬
‫دوره بلندمدت هوش تجاری‬

‫ تکمیلی‬DAX ‫جلسه‬

Site: DataToInsight.ir & www.imenpour.ir


Telegram: @Amir_imenpour, @DataToInsight, @MyBIgroup, @OKRcoach 1
Instagram: Amir_imenpour_official
LinkedIn: Amir imenpour
1
COMBINEVALUES ‫تابع‬

Joins two or more text strings into one text string. The primary purpose of this function is to
support multi-column relationships in DirectQuery models. See Remarks for details.
COMBINEVALUES(<delimiter>, <expression>, <expression>[, <expression>]…)

Term Definition
delimiter A separator to use during concatenation. Must be a constant value.
expression A DAX expression whose value will be be joined into a single text string.
Return value: A concatenated string.

Example:
DISTINCT (
SELECTCOLUMNS ( Date, "Month", COMBINEVALUES ( ", ", [MonthName], [CalendarYear] ) )
)
2
2
VALUE ‫تابع‬

3
VALUE ‫تابع‬

4
3

‫تابع‬
TIME

5
‫تابع‬
TIME

6
‫تابع‬
TIME

7
4

‫تابع‬
QUARTER

8
‫تابع‬
QUARTER

9
5

‫تابع‬
MONTH

10
‫‪6‬‬

‫تابع‬
‫‪DAY‬‬

‫‪11‬‬
‫تابع‬
‫‪DAY‬‬

‫‪12‬‬
7

‫تابع‬
YEARFRAC

13
8

‫تابع‬
DATEVALUE

14
9

‫تابع‬
TIMEVALUE

15
UTC

https://www.bahesab.ir/time/world/
https://www.asriran.com/fa/news/867751/%D8%B3%D8%
A7%D8%B9%D8%AA-
%D8%AC%D9%87%D8%A7%D9%86%DB%8C-
%DA%86%DB%8C%D8%B3%D8%AA-%D9%88-
%DA%86%DA%AF%D9%88%D9%86%D9%87-
%DA%A9%D8%A7%D8%B1-
%D9%85%DB%8C%E2%80%8C%DA%A9%D9%86%D8 16

%AF
10

UTCNOW ‫تابع‬

17
11

UTCTODAY ‫تابع‬

18
12
HOUR ‫تابع‬

19
13
MINUTE ‫تابع‬

20
14
SECOND ‫تابع‬

21
15
EDATE ‫تابع‬

22
16
EOMONTH ‫تابع‬

23
NETWORKDAYS ‫تابع‬
17

24
NETWORKDAYS ‫تابع‬

25
NETWORKDAYS ‫تابع‬

26
NETWORKDAYS ‫مقاله پیشنهادی برای تابع‬

https://www.mssqltips.com/sqlservertip/7359/calculating-
work-days-power-bi-dax-networkdays-function/

27
18
ABS ‫تابع‬
Returns the absolute value of a number.
ABS(<number>)

28
19
ROUND ‫تابع‬
Rounds a number to the specified number of digits.
ROUND(<number>, <num_digits>)

29
ROUND ‫تابع‬

30
20
ROUNDDOWN ‫تابع‬
Rounds a number down, toward zero.
ROUNDDOWN(<number>, <num_digits>)

31
ROUNDDOWN ‫تابع‬

32
21
ROUNDUP ‫تابع‬
Rounds a number up, away from 0 (zero).
ROUNDUP(<number>, <num_digits>)

33
ROUNDUP ‫تابع‬

34
22
MROUND ‫تابع‬
Returns a number rounded to the desired multiple.
MROUND(<number>, <multiple>)

35
MROUND ‫تابع‬

36
23
RAND ‫تابع‬
Returns a random number greater than or equal to 0 and less than 1, evenly distributed. The number
that is returned changes each time the cell containing this function is recalculated.
RAND()

37
ROUNDUP ‫تابع‬

38
24
RANDBETWEEN ‫تابع‬
Returns a random number in the range between two numbers you specify.
RANDBETWEEN(<bottom>,<top>)

39
25
TRUNC ‫تابع‬

Truncates a number to an integer by removing the decimal, or fractional, part of the number.
TRUNC(<number>,<num_digits>)

40
TRUNC ‫تابع‬

41
26
INT ‫تابع‬

Rounds a number down to the nearest integer.


INT(<number>)

42
27
CONVERT ‫تابع‬
Converts an expression of one data type to another.
CONVERT(<Expression>, <Datatype>)

43
‫‪28‬‬ ‫تابع ‪OR‬‬

‫‪44‬‬
29
COALESCE ‫تابع‬

45
COALESCE ‫تابع‬

46
30
IF.EAGER ‫تابع‬

47
IF.EAGER ‫تابع‬

48
31
DATATABLE ‫تابع‬

Provides a mechanism for declaring an inline set of data values.


DATATABLE (ColumnName1, DataType1, ColumnName2, DataType2..., {{Value1, Value2...}, {ValueN, ValueN+1...}...})

49
DATATABLE ‫تابع‬

50
32
FILTERS ‫تابع‬
Returns the values that are directly applied as filters to columnName.
FILTERS(<columnName>)

51
33

ADDMISSINGITEMS ‫تابع‬

Adds rows with empty values to a table returned


by SUMMARIZECOLUMNS.

ADDMISSINGITEMS ( [<showAll_columnName> [,
<showAll_columnName> [, … ] ] ], <table> [,
<groupBy_columnName> [, [<filterTable>] [,
<groupBy_columnName> [, [<filterTable>] [, … ] ] ] ] ] ] )

52
ADDMISSINGITEMS ‫تابع‬

53
ADDMISSINGITEMS ‫تابع‬

54
ORDERBY ‫تابع‬ 34

Defines the expressions that determine the sort


order within each of a window function’s
partitions.
ORDERBY ( [<orderBy_expression>[, <order>[,
<orderBy_expression>[, <order>]] …]] )

55
35

PARTITIONBY ‫تابع‬

56
36

MATCHBY ‫تابع‬

57
37 OFFSET ‫تابع‬

58
OFFSET ‫تابع‬

59
OFFSET ‫تابع‬

Return value
One or more rows from <relation>.
Remarks
Except for columns added by DAX table functions, each column in <relation>, when
<matchBy> is not present, or each column in <matchBy> and <partitionBy>, when
<matchBy> is present, must have a corresponding outer value to help define the current
row on which to operate, with the following behavior:
•If there is exactly one corresponding outer column, its value is used.
•If there is no corresponding outer column, then:
• OFFSET will first determine all columns that have no corresponding outer column.
• For every combination of existing values for these columns in OFFSET’s parent
context, OFFSET is evaluated and a row is returned.
• OFFSET’s final output is a union of these rows.
•If there is more than one corresponding outer column, an error is returned.
60
OFFSET ‫تابع‬

If all of <relation>'s columns were added by DAX table functions, an error is returned.
If <matchBy> is present, OFFSET will try to use <matchBy> and <partitionBy> columns to identify
the row.
If <matchBy> is not present and the columns specified within <orderBy> and <partitionBy> can't
uniquely identify every row in <relation>, then:
• OFFSET will try to find the least number of additional columns required to uniquely identify
every row.
• If such columns can be found, OFFSET will automatically append these new columns to
<orderBy>, and each partition is sorted using this new set of OrderBy columns.
• If such columns cannot be found, an error is returned.
An empty table is returned if:
• The corresponding outer value of an OrderBy or PartitionBy column does not exist within
<relation>.
• The <delta> value causes a shift to a row that does not exist within the partition.
If OFFSET is used within a calculated column defined on the same table as <relation>, and
<orderBy> is omitted, an error is returned. 61
1 ‫ مثال‬:OFFSET ‫تابع‬

DEFINE
VAR vRelation = SUMMARIZECOLUMNS (
DimProductCategory[EnglishProductCategoryName],
DimDate[CalendarYear], Returns a table that
"CurrentYearSales", SUM(FactInternetSales[SalesAmount])
)
summarizes the total sales
EVALUATE for each product category
ADDCOLUMNS ( and calendar year, as well
vRelation, as the total sales for that
"PreviousYearSales", category in the previous
SELECTCOLUMNS(
OFFSET (
year.
-1,
vRelation,
ORDERBY([CalendarYear]),
PARTITIONBY([EnglishProductCategoryName])
),
[CurrentYearSales] 62

)
)
2 ‫ مثال‬:OFFSET ‫تابع‬

DEFINE
MEASURE DimProduct[CurrentYearSales] = SUM(FactInternetSales[SalesAmount])
MEASURE DimProduct[PreviousYearSales] =
CALCULATE(SUM(FactInternetSales[SalesAmount]), OFFSET(-1, ,
ORDERBY(DimDate[CalendarYear])))
EVALUATE
SUMMARIZECOLUMNS (
DimDate[CalendarYear],
"CurrentYearSales", DimProduct[CurrentYearSales],
"PreviousYearSales", DimProduct[PreviousYearSales]
)

Uses OFFSET() in a measure to return a table that summarizes the total sales for each
calendar year and the total sales for the previous year.

63
3 ‫ مثال‬:OFFSET ‫تابع‬

EVALUATE
ADDCOLUMNS (
FactInternetSales,
Returns FactInternetSales table with
"Previous Sales Amount", adding a column, which indicates,
SELECTCOLUMNS ( for each sale, its previous sale's
OFFSET ( amount, of the same product, in
-1, descending order of sales amount,
FactInternetSales,
ORDERBY ( FactInternetSales[SalesAmount], DESC ),
with current sale being identified by
PARTITIONBY ( FactInternetSales[ProductKey] ), its SalesOrderNumber and
MATCHBY( FactInternetSales[SalesOrderNumber], SalesOrderLineNumber. Without
FactInternetSales[SalesOrderLineNumber] ) MATCHBY, the query would return
), an error since there are no key
FactInternetSales[SalesAmount]
)
columns in FactInternetSales table.
)

64

You might also like