You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Power BI查询编辑器中用DAX拆分表格并保留原表的方法

Power BI中用DAX生成Buy/Sell子表(保留主表)

我是Power BI新手,现有如下结构的主表:

Counterparty  Product  Deal  Date          Value
foo           bar      Buy    01/01/24     10.00
foo           bar      Buy    01/01/24     10.00
foo           bar      Sell   01/01/24     10.00
foo           bar      Sell   01/01/24     10.00
fizz          buzz     Buy    01/01/24     10.00
fizz          buzz     Buy    01/01/24     10.00
fizz          buzz     Sell   01/01/24     10.00
fizz          buzz     Sell   01/01/24     10.00

需要生成两个子表,分别保留Deal为Buy和Sell的记录:

Buy子表

Counterparty  Product  Deal  Date          Value
foo           bar      Buy    01/01/24     10.00
foo           bar      Buy    01/01/24     10.00
fizz          buzz     Buy    01/01/24     10.00
fizz          buzz     Buy    01/01/24     10.00

Sell子表

Counterparty  Product  Deal  Date          Value
foo           bar      Sell   01/01/24     10.00
foo           bar      Sell   01/01/24     10.00
fizz          buzz     Sell   01/01/24     10.00
fizz          buzz     Sell   01/01/24     10.00

要求在查询编辑器中实现,且保留主表。我已能用Python pandas实现:

import pandas as pd

df = pd.DataFrame(dataset)
df = df[df['DealType'].eq('Buy/Sell')]

想了解对应的DAX实现方式。


DAX实现步骤

  1. 在Power BI桌面版中,点击左侧建模选项卡,选择新建表。
  2. 输入以下DAX公式创建Buy子表:
Buy子表 = FILTER('主表', '主表'[Deal] = "Buy")
  1. 同样,新建表并输入公式创建Sell子表:
Sell子表 = FILTER('主表', '主表'[Deal] = "Sell")

说明:

  • FILTER函数会筛选主表中符合条件的行,生成独立新表。
  • 替换公式中的'主表'为你实际的主表名称,若表名含空格或特殊字符,需用单引号包裹。
  • 生成的子表会自动关联主表,主表数据更新时,子表将同步更新,且主表本身不受任何修改。

内容的提问来源于stack exchange,提问作者iBeMeltin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 08:20:03