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

October 28 & 29: Experts share their secrets on how to pass the Fabric Analytics Engineer certification exam—live. Learn more

Reply
wvdv
Frequent Visitor

Segment

Hi all,

I have the following dataset: 

MonthIDProduct Amount
1A-001X5
1A-001Y4
1A-002X1
1A-003X10
2A-001X1
2A-001Y4
2A-002X6
2A-003X4

 

I would like to create customer segments based on amount, but as you see the segment changes every month. For example customer A-001 would be in month 1 in segment 5-10 but in month 2 in segment 1-5

I have tried to segment but it takes into account the total amount of all months (customer A-001, total amount 14, segment 10 - 15)

Could anyone help? 
Thanks a lot!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but please try something like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1721670452444.png

 

Jihwan_Kim_1-1721670669463.png

 

Sales: = 
SUM( sales[Amount] )

 

Segment: = 
VAR _sales = [Sales:]
VAR _segment =
    FILTER ( Segment, Segment[min] <= _sales && Segment[max] >= _sales )
RETURN
    IF (
        HASONEVALUE ( 'ID'[ID] ) && HASONEVALUE ( 'Month'[Month] ),
        MAXX ( _segment, Segment[Category] )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

2 REPLIES 2
Samarth_18
Community Champion
Community Champion

Hi @wvdv ,

 

You can create a segment table(SegmentRanges) based on your range. so based on your sample, I have created a sample table as below:-

Samarth_18_0-1721671437978.png

Now create a measure as below:-

Segment =
VAR CurrentMonth =
    MAX ( SalesData[Month] )
VAR CurrentAmount =
    CALCULATE (
        SUM ( SalesData[Amount] ),
        FILTER (
            ALL ( Salesdata ),
            Salesdata[Month] = CurrentMonth
                && Salesdata[ID] = MAX ( Salesdata[ID] )
        )
    )
RETURN
    CALCULATE (
        MAX ( SegmentRanges[Segment] ),
        FILTER (
            SegmentRanges,
            CurrentAmount >= SegmentRanges[Lower Bound]
                && CurrentAmount <= SegmentRanges[Upper Bound]
        ),
        Salesdata[Month] = CurrentMonth
    )

output:-

Samarth_18_1-1721671664390.png

 

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but please try something like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1721670452444.png

 

Jihwan_Kim_1-1721670669463.png

 

Sales: = 
SUM( sales[Amount] )

 

Segment: = 
VAR _sales = [Sales:]
VAR _segment =
    FILTER ( Segment, Segment[min] <= _sales && Segment[max] >= _sales )
RETURN
    IF (
        HASONEVALUE ( 'ID'[ID] ) && HASONEVALUE ( 'Month'[Month] ),
        MAXX ( _segment, Segment[Category] )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

October NL Carousel

Fabric Community Update - October 2024

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