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
TanzilHasan
Frequent Visitor

Group Customer by Order type

Hi All, 

 

I have a data set that includes customer ID, order number, order date, and order type. The order type has three possible values: free, paid, and mixed. For example, a single customer may place orders of all three types on different dates.

 

I want to analyze how many customers have placed orders in specific categories during a reporting period: only paid orders, only free orders, free and paid orders, and orders that include all three types. I attempted to achieve this using Power Query but got stuck along the way.

 

How do I solve this?

Sample data:

 

Customer IDOrder NoOrder DateOrder Type
CUST001ORD10011/11/2024Paid
CUST001ORD100210/11/2024Free
CUST001ORD100315/11/2024Mixed
CUST002ORD10043/11/2024Free
CUST002ORD100512/11/2024Paid
CUST003ORD10062/11/2024Mixed
CUST003ORD10078/11/2024Free
CUST003ORD100820/11/2024Paid
CUST004ORD10095/11/2024Paid
CUST004ORD101018/11/2024Mixed
CUST005ORD10117/11/2024Free
CUST005ORD101214/11/2024Paid
CUST006ORD10131/11/2024Mixed
CUST006ORD101411/11/2024Mixed
CUST007ORD10156/11/2024Free
CUST007ORD101619/11/2024Paid
CUST008ORD10174/11/2024Free
CUST008ORD101815/11/2024Paid
CUST009ORD10199/11/2024Mixed
CUST009ORD102021/11/2024Paid

 

Expected data:

Customer IDCustomer Type
CUST001All Three
CUST003All Three
CUST002Free and Paid
CUST005Free and Paid
CUST007Free and Paid
CUST008Free and Paid
CUST004Only Paid
CUST004Paid and Mixed
CUST009Paid and Mixed
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @TanzilHasan,

Thanks for reaching out Microsoft fabric community forum.


As per your query, follow the below steps to achieve you goal.

I used the above data. I imported data into power query editor and in transform data i have done group by customer id and order type. 

vshamiliv_0-1733903456977.png

vshamiliv_1-1733903496226.png

A separate table is created for each customer 

Add custom column .use the below code in formula bar 

Text.Combine(List.Distinct([Order Types][Order Type]), ", ") 

vshamiliv_2-1733903580132.png

Add another custom column by using the below code in formula bar:

if Text.Contains([Custom], "Paid") and Text.Contains([Custom], "Free") and Text.Contains([Custom], "Mixed") then "All Three"
else if Text.Contains([Custom], "Paid") and Text.Contains([Custom], "Free") then "Free and Paid"
else if Text.Contains([Custom], "Paid") and Text.Contains([Custom], "Mixed") then "Paid and Mixed"
else if Text.Contains([Custom], "Paid") then "Only Paid"
else if Text.Contains([Custom], "Free") then "Only Free"
else "Other"

vshamiliv_3-1733903603420.png

 

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

Thank you 

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @TanzilHasan,

Thanks for reaching out Microsoft fabric community forum.


As per your query, follow the below steps to achieve you goal.

I used the above data. I imported data into power query editor and in transform data i have done group by customer id and order type. 

vshamiliv_0-1733903456977.png

vshamiliv_1-1733903496226.png

A separate table is created for each customer 

Add custom column .use the below code in formula bar 

Text.Combine(List.Distinct([Order Types][Order Type]), ", ") 

vshamiliv_2-1733903580132.png

Add another custom column by using the below code in formula bar:

if Text.Contains([Custom], "Paid") and Text.Contains([Custom], "Free") and Text.Contains([Custom], "Mixed") then "All Three"
else if Text.Contains([Custom], "Paid") and Text.Contains([Custom], "Free") then "Free and Paid"
else if Text.Contains([Custom], "Paid") and Text.Contains([Custom], "Mixed") then "Paid and Mixed"
else if Text.Contains([Custom], "Paid") then "Only Paid"
else if Text.Contains([Custom], "Free") then "Only Free"
else "Other"

vshamiliv_3-1733903603420.png

 

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

Thank you 

 

Thank you so much, this solution works. 

Kedar_Pande
Super User
Super User

@TanzilHasan 

Create a Calculated Columns:

UniqueOrderTypes = 
CONCATENATEX(
DISTINCT('Orders Table'[Order Type]),
'Orders Table'[Order Type],
", "
)
CustomerType = 
SWITCH(
TRUE(),
'Orders Table'[UniqueOrderTypes] = "Free, Paid, Mixed", "All Three",
'Orders Table'[UniqueOrderTypes] = "Free, Paid", "Free and Paid",
'Orders Table'[UniqueOrderTypes] = "Paid, Mixed", "Paid and Mixed",
'Orders Table'[UniqueOrderTypes] = "Free, Mixed", "Free and Mixed",
'Orders Table'[UniqueOrderTypes] = "Paid", "Only Paid",
'Orders Table'[UniqueOrderTypes] = "Free", "Only Free",
'Orders Table'[UniqueOrderTypes] = "Mixed", "Only Mixed",
"Other"
)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

 

Thanks mate, this solution also works. 

Irwan
Super User
Super User

hello @TanzilHasan 

 

please check if this accomodate your need.

 

create new table for summarize your original data.

Irwan_0-1733880447730.png

Summarize =
SUMMARIZE(
    ADDCOLUMNS(
        SUMMARIZE(
            'Table',
            'Table'[Customer ID],
            "Type",
            CONCATENATEX(
                'Table',
                'Table'[Order Type],
                " ",
                'Table'[Index],
                DESC
            )
        ),
        "Customer Type",
        IF(
            [Type]="Mixed Free Paid",
            "All Three",
            SUBSTITUTE(
                [Type],
                " ",
                " and "
            )
        )
    ),
    'Table'[Customer ID],
    [Customer Type]
)
 

Hope this will help.

Thank you.

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.