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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
TrangHoThu
Frequent Visitor

How many customers did order full 3 sections, how many two times, how many three times and so on?

Hello community

I had problem with calculating how many customers did order full 3 sections, how many two times, how many three times and so on?

For example: The result I expected like: 2 customer have order 3 sections and one times.

I dont know how to calculate it. please help me solve this case.

TrangHoThu_2-1673515806499.png

 

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @TrangHoThu ,

 

One way to do this is by double-grouping table.

First, group by [Customer] and [Sale Document] and add a Distinct Count aggregation so we know how many sections were ordered in each customer transaction.

Then, group by [Customer] and your first Distinct Count column, adding another Distinct Count column so we know how many times each customer ordered each number of sections.

 

This example query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8snMqVTSUTIEYkelWB0UASd0AWewgGNeXiKQYwTXgiQA0eKaC9FjDFeCLIKpxhnZIhN0p5ig22wKNwRJAMUMM3QzzNC9YwbREgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, SaleDocument = _t, Section = _t]),
    
    groupCustomerDocument = Table.Group(Source, {"Customer", "SaleDocument"}, {{"NumberSectionsOrdered", each Table.RowCount(Table.Distinct(_)), Int64.Type}}),
    groupCustomerSectionOrdered = Table.Group(groupCustomerDocument, {"Customer", "NumberSectionsOrdered"}, {{"NumberTimesSectionsOrdered", each Table.RowCount(Table.Distinct(_)), Int64.Type}})
in
    groupCustomerSectionOrdered

 

...turns this:

BA_Pete_0-1673518247159.png

 

...into this:

BA_Pete_1-1673518334855.png

 

...so we can see:

Anna has ordered 2 sections twice

Emily has ordered 3 sections once

Lily has ordered 2 sections once, and 3 sections twice

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
TrangHoThu
Frequent Visitor

That worked! Thanks a lot

BA_Pete
Super User
Super User

Hi @TrangHoThu ,

 

One way to do this is by double-grouping table.

First, group by [Customer] and [Sale Document] and add a Distinct Count aggregation so we know how many sections were ordered in each customer transaction.

Then, group by [Customer] and your first Distinct Count column, adding another Distinct Count column so we know how many times each customer ordered each number of sections.

 

This example query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8snMqVTSUTIEYkelWB0UASd0AWewgGNeXiKQYwTXgiQA0eKaC9FjDFeCLIKpxhnZIhN0p5ig22wKNwRJAMUMM3QzzNC9YwbREgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, SaleDocument = _t, Section = _t]),
    
    groupCustomerDocument = Table.Group(Source, {"Customer", "SaleDocument"}, {{"NumberSectionsOrdered", each Table.RowCount(Table.Distinct(_)), Int64.Type}}),
    groupCustomerSectionOrdered = Table.Group(groupCustomerDocument, {"Customer", "NumberSectionsOrdered"}, {{"NumberTimesSectionsOrdered", each Table.RowCount(Table.Distinct(_)), Int64.Type}})
in
    groupCustomerSectionOrdered

 

...turns this:

BA_Pete_0-1673518247159.png

 

...into this:

BA_Pete_1-1673518334855.png

 

...so we can see:

Anna has ordered 2 sections twice

Emily has ordered 3 sections once

Lily has ordered 2 sections once, and 3 sections twice

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors