Power BI Query Error: The column either doesn't exist or doesn't have a relationship to any table available in the current context

Power BI Query Error: The column either doesn't exist or doesn't have a relationship to any table available in the current context

我有一个 table 有客户交易。我需要为每一行创建一个新列:

  1. 如果它是'customer id'的第一次出现,它将有"Onboarding"
  2. 如果它是'customer id'的最后一次出现,它将有"Offboarding"
  3. 剩下的就是"Existing"

下面是我尝试过的 DAX 代码:

Customer Churn =
IF (
    Book[Date]
        = LOOKUPVALUE ( Book[Date].[Date], Book[customer id], FIRSTDATE ( Book[Date] ) ),
    "Onboarding",
    IF (
        Book[Date]
            = LOOKUPVALUE ( Book[Date].[Date], Book[customer id], LASTDATE ( Book[Date] ) ),
        "Offboarding",
        "Existing"
    )
)

但我收到以下错误:

The column 'Book[customer id]' either doesn't exist or doesn't have a relationship to any table available in the current context.

无法考虑使用 RELATED(),因为我指的是相同的 table。

问题出在哪里? 如果无法以这种方式编码,有什么解决方法吗?

谢谢!

在一些帮助下我得到了解决方案。参考dax/lookupvalue-function-dax,你会发现原脚本中的错误。 search_columnName 和 search_value 是一对。

LOOKUPVALUE( <result_columnName>, <search_columnName>, <search_value>[, <search_columnName>, <search_value>]…)  

所以公式无法return得到正确的结果。

LOOKUPVALUE ( Book[Date].[Date], Book[customer id], FIRSTDATE ( Book[Date] ) )

解法:

Customer Churn =
   VAR startDate =
      CALCULATE ( FIRSTDATE ( Book[Date] ), ALLEXCEPT ( Book, Book[Customer Id] ) )
   VAR endDate =
      CALCULATE ( LASTDATE ( Book[Date] ), ALLEXCEPT ( Book, Book[Customer Id] ) )
RETURN
IF (
    Book[Date]
        = LOOKUPVALUE (
            Book[Date],
            Book[customer id], [Customer Id],
            Book[Date], startDate
        ),
    "Onboarding",
    IF (
        Book[Date]
            = LOOKUPVALUE (
                Book[Date],
                Book[customer id], [Customer Id],
                Book[Date], endDate
            ),
        "Offboarding",
        "Existing"
    )
)