DAX 查询以获取首次购买的客户总数

DAX Query for getting Total customer who made first Purchase

我是 Power BI-DAX 查询的新手,能否请您帮我解决以下问题。

我在 Excel 中有包含以下列的客户数据,我需要使用 DAX 查询找出日期和月份首次购买的客户总数: 列是 - DateFirstPurchase、CustomerKey、FirstName、lastName

CustomerData

我正在寻找如下输出:-

DateFirstPurchase   Number of Customer
   Jan 11             2

等等.......

**Sample Customer Data in Excel sheet :**
DateFirstPurchase   CustomerKey FirstName   last Name
1/11/2004 0:00      11602   Larry   Gill
4/21/2004 0:00      12517   Alexa   Watson
2/2/2004 0:00       12518   Jacquelyn   Dominguez
1/20/2004 0:00      12714   Colleen Lu
5/12/2004 0:00      12871   Leah    Li
1/11/2004 0:00      13830   Andrea  Cox
3/14/2004 0:00      13838   Jill    Rubio
2/2/2004 0:00       14839   Natasha Sanz
8/25/2003 0:00      14840   Autumn  Zhu
11/12/2002 0:00     14848   George  Louverdis
10/12/2003 0:00     16453   Mayra   Chandra
2/2/2004 0:00       16458   Michele Ruiz
12/17/2003 0:00     16460   Jodi    Xu
2/11/2002 0:00      18038   Kelli   Kumar
8/25/2003 0:00      19371   Roy     Mehta

您可以创建一个新的 table:

并使用这样的代码来计算新的 table:

new_table = SUMMARIZE('existing_table', 'existing_table'[DateFirstPurchase].[MonthNo], 'existing_table'[DateFirstPurchase].[Year], "Number of customers", COUNTROWS('existing_table'))

结果 看起来像:

如果您想要一个包含 2019 - 122017 - 11 等值的列,您可以在创建的 table:

中添加一个新列
Month = 'new_table'[Year] & " - " & 'new_table'[MonthNo]

结果:

更新, 你也可以在 Power Query:

右击日期栏

之后 Transform -> Group by:

你可以使用这个措施

Measure =
COUNTROWS (
    EXCEPT (
        VALUES ( 'Table'[CustID] ),
        SUMMARIZE (
            FILTER (
                ALL ( 'Table' ),
                'Table'[DateFirstPurchase] < MAX ( 'Table'[DateFirstPurchase] )
            ),
            'Table'[CustID]
        )
    )
)