维度的每个值的 DAX 筛选逻辑

DAX Filtering Logic For Each Value of a Dimension

在 DAX 中 - 生成所需输出的最有效方法是什么:

我想说这类似于 SQL 中的相关子查询。

OPTION-1

步骤 1: 创建一个 自定义列 如下-

is_min_date = 

// -- keep current row's customer id to a variable
VAR current_cust_id = store[Customer ID]
// -- keep current row's YEAR value to a variable
VAR current_date = store[Order Date]

// -- find the MIN YEAR from order date for the current row customer id
VAR min_date_current_custommer_id =  
CALCULATE(
    MIN(store[Order Date]),
    FILTER(
       store,
        store[Customer ID] = current_cust_id
    )
)

// -- check the current row's year is the MIN year of order date for the customer as well or not.
RETURN IF(current_date = min_date_current_custommer_id, 1,0)

第 2 步: 现在在您的视觉对象中添加一个基本过滤器,如下所示,您将在 table 视觉对象-

中获得所需的行

OPTION 2: The same can be achieved using Measure as well instead of creating a Custom Column. Just do this below-

步骤 1: 创建如下度量 -

is_min_date_measure = 

VAR min_order_date_for_current_customer = 
CALCULATE(
    MIN(store[Order Date]),
    FILTER(
        ALL(store),
        store[Customer ID] = MIN(store[Customer ID])
    )
)

RETURN
IF ( MIN(store[Order Date]) = min_order_date_for_current_customer, 1,0)

Step-2:现在添加视觉级别过滤器如下,你会得到你想要的输出-