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

Power BI中能否用DAX实现逆透视?如何无需Power Query用DAX创建指定图表?

Answers to Your Power BI DAX Questions

Hey Nils, great questions! Let's break this down clearly so you can implement what you need.

1. Can You Unpivot Data Using DAX in Power BI?

Short answer: Yes, you can simulate unpivoting with DAX, even though there's no dedicated UNPIVOT function like in Power Query. The trick is to use a combination of UNION, SELECTCOLUMNS, or GENERATE to convert column-based data into row-based data.

For example, if you have a table Sales with columns Date, ProductA_Sales, ProductB_Sales, you can create an unpivoted calculated table like this:

Unpivoted_Sales = 
UNION(
    SELECTCOLUMNS(Sales, 
        "TransactionDate", Sales[Date], 
        "Product", "Product A", 
        "SalesAmount", Sales[ProductA_Sales]
    ),
    SELECTCOLUMNS(Sales, 
        "TransactionDate", Sales[Date], 
        "Product", "Product B", 
        "SalesAmount", Sales[ProductB_Sales]
    )
)

If you have more columns to unpivot, you can use GENERATE with VALUES to make it more dynamic (just be mindful of performance with very large datasets, as calculated tables refresh with your model).

2. Building Target Charts with DAX (No Power Query, Using Two Tables + Calendar Table)

Assuming you have a fact table (e.g., transaction data), a dimension table (e.g., product/region details), and a calendar table, here's a step-by-step implementation plan:

Step 1: Validate Table Relationships

First, make sure your tables are properly related in the data model:

  • Link your fact table's date column to your calendar table's date column (one-to-many relationship, calendar on the "one" side)
  • Link your fact table's dimension key (e.g., ProductID) to your dimension table's matching key (e.g., ProductID)

Step 2: Create DAX Calculated Tables (If Needed)

If your source data is pivoted (like the example above), use the unpivoting method from question 1 to create a row-based calculated table that's easier to visualize.

Step 3: Build DAX Measures for Your Chart

Create the metrics you need for the chart using context-aware DAX functions. For example:

Total Sales = SUM(Unpivoted_Sales[SalesAmount])

YoY Sales Growth = 
VAR CurrentPeriodSales = [Total Sales]
VAR PriorYearSales = CALCULATE([Total Sales], DATEADD(Calendar[Date], -1, YEAR))
RETURN
DIVIDE(CurrentPeriodSales - PriorYearSales, PriorYearSales, 0) // Returns 0 if prior year has no data

Step 4: Assemble the Chart

In the Power BI report view:

  • Drag a date field from your calendar table (e.g., Year-Month) to the chart's axis
  • Drag a dimension field (e.g., Product Name from your dimension table) to the legend
  • Drag your DAX measure (e.g., Total Sales) to the values area
  • Add slicers from the calendar table (e.g., Year) or dimension table (e.g., Region) to let users filter the data dynamically

This approach keeps all transformations within DAX and leverages your existing tables + calendar table to build the exact chart you need.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:52:53