# 【王者之战】Tableau LOD和Power BI DAX函数案例对比

Tableau Include和Power Bi summarize函数 最近阅读《the definitive guide to DAX》（中文《DAX圣经》），第四章中讲解了一个典型案例，借此介绍了SUMMARIZE函数，这里笔记整理如下，并借此说明PBI与Tableau在处理“多个详细级别问题”时的方法差异。

## 1、问题解析

Compute the average age of customers at the time of sale, counting each customer only once if they made multiple purchases at the same age .

## 2、PBI的解答方法

``````SALES[customer Age] =
DATEDIFF(                --compute the difference between
RELATED(Customer[birth Date] ),     -- the customer's birth date
Sales[Order Date],                  -- and the order date
YEAR                                -- in year
)``````

``Avg Customer Age Wrong := AVERAGE (SALES[customer Age] )``

``````Avg Customer Age Wrong :=
AVERAGEX ( -- iterate on the distinct values of customer age
DISTINCT (Sales[customer Age]),
SALES[customer Age] )``````

``````Avg Customer Age correct:=
AVERAGEX ( -- iterate on
SUMMARIZE( --all the existing combinaiton
Sales, -- that exist in Sales
Sales[customer ID], -- of the customer id and
Sales[customer Age], -- the customer age
)
SALES[customer Age] ) -- and average the customer's age
)``````

## 3、Tableau 的解答方法

``AVG( {FIXED [Sub-Category],[Customer Name],[消费年龄]: avg([消费年龄])})``

``AVG( {INCLUDE [Customer Name],[消费年龄]: avg([消费年龄])})``

``````Avg Customer Age correct:=
AVERAGEX (                           -- iterate on
SUMMARIZE(                           --all the existing combinaiton
Sales, -- that exist in Sales
Sales[customer ID],               -- of the customer id and
Sales[customer Age],                 -- the customer age
)
SALES[customer Age] )                   -- and average the customer's age
)``````