每个维度值的DAX过滤逻辑

问题描述

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

enter image description here

我想说的是,这类似于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步:现在,在可视画面中添加如下所示的基本过滤器,您将在表格的可视画面中获得所需的行-

enter image description here

选项2: 也可以使用“测量”代替创建“自定义列”来实现相同目的。只需在下面执行此操作即可

步骤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,0)

步骤2:现在,如下所示添加视觉级别过滤器,您将获得所需的输出-

enter image description here

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...