Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How to segment customers by number of transactions by a new table

Hi,

 

I would like to know how to create this auxiliar table where I have a count of each unique customers displayed by how many times they completed a transaction. 

 

Many thanks in advance,

Rui

RMSLUIS_0-1668099789551.jpeg

 

 

1 ACCEPTED SOLUTION

Hi, @Anonymous 

 

Column:

Segment = SWITCH(True(),
[Transaction]>=4,"High",
[Transaction]<4&&[Transaction]>=2,"Medium",
[Transaction]<=1,"Low")

vzhangti_0-1668391141790.png

vzhangti_1-1668391169193.png

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
zerotyper
Frequent Visitor

@v-zhangti  I'd like to borrow your file, thanks!

@Anonymous 

1st, create a table via the below code :

Segment = 
SELECTCOLUMNS(
   { 
       ( "High", 1  ) ,
       ( "Medium" , 2 ) ,
       ( "Low" ,3 )
   } ,
    "Segment" , [Value1] , "Orderby" , [Value2]
)

2nd, create a measure

# Customers = 
VAR _customerTbl =
    ADDCOLUMNS (
        VALUES ( 'Transaction'[Customer ID] ),
        "@Transaction",
            CALCULATE (
                DISTINCTCOUNT ( 'Transaction'[Transaction ID] )
            )
    )
VAR _Segment =
    MAX ( 'Segment'[Segment] )
RETURN
IF(
    HASONEVALUE( 'Segment'[Segment] ) ,
    SWITCH (
        TRUE (),
        _Segment = "High",
            COUNTROWS (
                FILTER (
                    _customerTbl,
                    [@Transaction] >= 4
                )
            ),
        _Segment = "Medium",
            COUNTROWS (
                FILTER (
                    _customerTbl,
                    [@Transaction] >= 2
                        && [@Transaction] < 4
                )
            ),
        COUNTROWS (
            FILTER (
                _customerTbl,
                [@Transaction] < 2
            )
        )
    ),
    COUNTROWS( _customerTbl )
)

3rd, put the column Segment[Segment] and measure into Matrix.

zerotyper_0-1668168073091.png

 

 

v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.

Table:

Table 2 =
SUMMARIZE (
    'Table',
    'Table'[Customer ID],
    "Transaction",
        CALCULATE (
            COUNT ( 'Table'[Customer ID] ),
            ALLEXCEPT ( 'Table', 'Table'[Customer ID] )
        )
)

Column:

Customer = CALCULATE(COUNT('Table 2'[Transaction]),ALLEXCEPT('Table 2','Table 2'[Transaction]))

vzhangti_0-1668132792000.png

Result:

vzhangti_1-1668132814603.png

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi,

 

It works perfectly (by table).

If I want in the same table to add a new collum where I segment the customers by frequency. I mean like this....

RMSLUIS_1-1668162501630.png

Thank you very much!

Rui

 

 

 

Hi, @Anonymous 

 

Column:

Segment = SWITCH(True(),
[Transaction]>=4,"High",
[Transaction]<4&&[Transaction]>=2,"Medium",
[Transaction]<=1,"Low")

vzhangti_0-1668391141790.png

vzhangti_1-1668391169193.png

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.