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
Anonymous
Not applicable

Segment by sum of quantity and number of customers per segment

Hi Experts,

 

I have a fact table looking like this:

 

Orders

 

date                                                            customerid                       qty

27-02-201921
27-02-201926
27-02-201934
27-02-201932
27-02-201934
10-03-201916
10-03-201912
10-03-201932
10-03-201911

 

I would like to segment into quantity segments, showing number of customers in each segment. The segments are by quantity and result should like below:

 

Quantity segment                                                       February                  March

Quantity 111
Quantity 202
Quantity 300
Quantity 420
Quantity 5 or more!11

 

The date columns february and march are showing number of customers per segment.

 

I've been looking at https://www.daxpatterns.com/static-segmentation/ and https://www.daxpatterns.com/dynamic-segmentation/ for inspiration - but I can't seem to get around a way of doing it. Any hints, help or advice to what DAX pattern is correct would highly appreciated.

 

I should hope to end up with a visual like the one below:

 

 

bla.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best wishes and hope - from:

 

Jon

11 REPLIES 11
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Is this problem sloved?

If not, please let me know.

 

Best Regards

Maggie

 

Community Support Team _ Maggie Li
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 Maggie,

 

So kind of you to follow up. Problem is still not solved 😞

 

What I want to do is:

 

Create 5 named segments/buckets.

 

For each row in Orders Table:

      Get value of field Quantity

 

Then - for visualization: Sum all quantity fields for a customer - and check where that sum fits within the defined segment bucket.. For example:

 

During week 42, user DanJohnson has 3 orders, 2 with quantity of 3 and one with quantity of 5. In total: quantity 11. 11 fits in to segment5 which has values 5 and above.

 

Hopefully,

Jon

Hi,

 

Have you checked my solution?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi Ashish,

 

I actully did - and thank you I appreciate your help.

 

Back then I couldn't make it work - but now.. I'll try again - it looks like it is actually the right thing. I'll check again - and come back 🙂

 

Jon

v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create columns

year = YEAR(Sheet1[date])

month = FORMAT(Sheet1[date],"MMMM")
Quantity segment = SWITCH(TRUE(),Sheet1[qty]=1,"Quantity 1",Sheet1[qty]=2,"Quantity 2",Sheet1[qty]=3,"Quantity 3",Sheet1[qty]=4,"Quantity 4",Sheet1[qty]>=5,"Quantity 5 or more")

Create measure

Measure = CALCULATE(DISTINCTCOUNT(Sheet1[customerid]),ALLEXCEPT(Sheet1,Sheet1[year],Sheet1[month],Sheet1[Quantity segment]))

3.png

 

Best Regards

Maggie

 

Community Support Team _ Maggie Li
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 Maggie,

 

I sorry I didn't make it clear. But the second table in my post is not something I have, but the result I wish.

 

So - in my model I only have a table called orders (a date table also exists).

 

- So I need to create segments (Quantity 1,2,3,4 and 5 and above) - and then find out how many customers belong to each quantity segment.

 

Does it make sense?

 

Jon

Hi @Anonymous 

I don't use the second table as the original table, i use the first table as the original table.

I use the first table from your post, then create measures and columns, thus i can create a matrix visual as the second table in your post by adding some columns and measure in a matrix.

 

Per your requirement, modify the measure i provide before as below

Measure = CALCULATE(DISTINCTCOUNT(Sheet1[customerid]),ALLEXCEPT(Sheet1,Sheet1[year],Sheet1[month],Sheet1[Quantity segment]))

Best Regards

Maggie

 

Community Support Team _ Maggie Li
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 Maggie,

 

Thank you for quick response.

 

I do not have the quantity segment in my dataset. It needs to be created. 

 

Segment 1: Quantity = 1

Segment 2: Quantity = 2

Segment 3: Quantity = 3

Segment 4: Quantity = 4

Segment 5: Quantity => 5

 

To me it looks like the pattern: https://www.daxpatterns.com/dynamic-segmentation/ where a parameter table is containing the segments.

 

So - for each week, month, quarter, year (every column in my date dimension table) I'd like to answer the question: what is the distribution of customers in each segment, for example how many customer did belong to Segment 1 in January 2019? 

 

Segments don't exist - they need to be created somehow. 

 

Jon

 

 

 

 

Hi,

 

You may download my PBI file from here.  Given the data ou have shared, the result should be

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Anonymous 

Download my file and see details.

 

Best Regards

Maggie

Hi @Anonymous 

See my first post, i update it just now.

 

Best Regards

Maggie

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.