简体   繁体   English

什么是Office 365中的Excel中的Power Pivot中的计算列中的正确DAX GROUPBY语法

[英]What is Proper DAX GROUPBY Syntax In Calculated Column in Power Pivot in Excel in Office 365

The following syntax entered into a calculated column formula for table Visits provided below in powerpivot in excel (office 365 version): 以下语法输入到excel(office 365版本)powerpivot中提供的表访问的计算列公式中:

=GROUPBY(  
   Visits,  
   [Patient Name],  
   "First_Visit_Date", 
   MINX(CURRENTGROUP(), Visits[Visit_Date])
 )

Yields the error: 产生错误:

The expression refers to multiple columns. Multiple columns cannot be 
converted to a scalar value.

What is the correct DAX GROUPBY syntax when using PowerPivot embedded in Excel to add a calculated column "First_Visit_Date" to the simple source table Visits table depicted below to arrive at the target table also listed below: 使用嵌入在Excel中的PowerPivot将计算列“First_Visit_Date”添加到简单源表时,正确的DAX GROUPBY语法是什么语法下面描述的Visits表到达下面列出的目标表:

Source Table (Visits): 来源表(访问量):

 Patient_Name, Visit_Date, Duration Sue, 8/10/2017, 60 Sue, 8/12/2017, 20 Sue, 8/20/2017, 15 Bill, 9/ 1/2018, 90 Bill, 10/ 1/2018, 90 Sally, 5/22/2016, 30 Sally, 5/30/2016, 30 

Target Table: 目标表:

 Patient_Name, Visit_Date, Duration, Calculated Column 1 Sue, 8/10/2017, 60, 8/10/2017 Sue, 8/12/2017, 20, 8/10/2017 Sue, 8/20/2017, 15, 8/10/2017 Bill, 9/ 1/2018, 90, 9/ 1/2018 Bill, 10/ 1/2018, 90, 9/ 1/2018 Sally, 5/22/2016, 30, 5/22/2016 Sally, 5/30/2016, 30, 5/22/2016 

Your syntax looks OK, but what you may not realize is that GROUPBY outputs a table, not a scalar value. 您的语法看起来没问题,但您可能没有意识到GROUPBY输出的是表,而不是标量值。

This is what your DAX returns if you enter it as a new table rather than a calculated column: 如果您将DAX作为新表而不是计算列输入,则这就是DAX返回的内容:

产量

For a calculated column you just want a DAX formula like this: 对于计算列,您只需要这样的DAX公式:

CalcCol =
CALCULATE(
    MIN(Visits[Visit_Date]),
    ALLEXCEPT(Visits, Visits[Patient_Name])
)

or like this: 或者像这样:

CalcCol =
MINX(
    FILTER(
        Visits,
        Visits[Patient_Name] = EARLIER(Visits[Patient_Name])
    ),
    Visits[Visit_Date]
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM