Skip to content

Commit 034241b

Browse files
committed
Add lookup function.
1 parent 469257f commit 034241b

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
description: "Learn more about: LOOKUP"
3+
title: "LOOKUP function (DAX) | Microsoft Docs"
4+
---
5+
# LOOKUP
6+
7+
Used in visual calculation only. The Lookup function allows user to retrieve a value in a cell in the visual matrix using absolute navigation. User can specify a value as filter for any axis on the visual matrix and anything not specified will be inferred from the context. If Lookup could not result in single value, it will return an error.
8+
9+
## Syntax
10+
11+
```dax
12+
LOOKUP(<column>[, <filter1> [, <filter2> [, …]]])
13+
```
14+
15+
### Parameters
16+
17+
|Term|Definition|
18+
|--------|--------------|
19+
|column| Only column reference is allowed, For example [Sales] is allowed, but [Sales][Cost] is not, nor is SUM([Sales]) |
20+
|filter1, filter2,…|(Optional) Filter has to be either: 1. An equality filter. For example [Year]=2019 or [Year]=MAX([Year]). 2.
21+
The Collapse function. For example, LOOKUP([Sales], Collapse([Country])) returns the subtotal value for Sales for all Countries|
22+
23+
## Return value
24+
25+
The value of **column** at the row after filters are applied.
26+
27+
If there isn't a match that satisfies all the search values, an error is returned.
28+
29+
If multiple rows match the filters, an error is returned.
30+
31+
## Example 1
32+
33+
In this example, LOOKUP retrieves the sum of sale easily when [Year] = 2006, [MonthNumberOfYear] = 1, [Month] = "January".
34+
35+
```dax
36+
// GB column references
37+
Define
38+
var _Core = SUMMARIZECOLUMNS(
39+
'DimDate'[Year],
40+
'DimDate'[Month], 'DimDate'[MonthNumberOfYear],
41+
'DimProduct'[ProductCategoryName],
42+
'DimProduct'[ProductSubcategoryName],
43+
"SumOfInternetSales", CALCULATE(SUM('FactInternetSales'[SalesAmount]))
44+
)
45+
table t = _Core
46+
with visual shape
47+
axis rows
48+
group [Year]
49+
group [Month], [MonthNumberOfYear]
50+
order by [Year], [MonthNumberOfYear]
51+
axis columns
52+
group [ProductCategoryName]
53+
group [ProductSubcategoryName]
54+
order by [ProductCategoryName], [ProductSubcategoryName]
55+
densify "isDensified"
56+
57+
column t[ccLookup] =
58+
lookup([SumOfInternetSales], [Year] = 2006, [MonthNumberOfYear] = 1, [Month] = "January")
59+
60+
evaluate selectcolumns(
61+
filter(t, not isblank([SumOfInternetSales])),
62+
[ProductCategoryName], [ProductSubcategoryName], [Year], [MonthNumberOfYear], [SumOfInternetSales], [ccLookup]
63+
)
64+
order by [ProductCategoryName], [ProductSubcategoryName], [Year], [MonthNumberOfYear]
65+
```

0 commit comments

Comments
 (0)