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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
JB17
Frequent Visitor

Please HELP create DAX

 

Hello Everyone,

Can you help me create measure for below?

I need to categorize the values based on support in the last five years:

if the product is supported in the last five years then the category would be "Loyal", 

if the product is supported only in current year then "New"

if the product is unsupported in the last five years then "former & non-purchasing"

if the product is supported 3 or 4 out of the last 5 years then "potentially loyal"

if the product is supported 2 or 1 out of the last 5 years but not in the current year then "transient"

sample illustration is below:

 

JB17_1-1693889823302.png

Your help will be greatly appreciated! 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @JB17 ,

 

I created some data:

vyangliumsft_0-1694052755352.png

 

Here are the steps you can follow:

1. Create calculated column.

Flag =
var _yearcurrent=YEAR(TODAY())
var _count=
CALCULATE(DISTINCTCOUNT('Table'[Year]),
FILTER(ALL('Table'),'Table'[Group]=EARLIER('Table'[Group])&&'Table'[support]="yes"&&'Table'[Year]>=_yearcurrent-4&&'Table'[Year]<=_yearcurrent))
return
SWITCH(
    TRUE(),
    _count=5,"Loyal",
    _count>=3&&_count<=4&&
    CALCULATE(DISTINCTCOUNT('Table'[Year]),
FILTER(ALL('Table'),'Table'[Group]=EARLIER('Table'[Group])&&'Table'[support]="yes"&&'Table'[Year]=_yearcurrent))=0,"Potentially Loyal",
    _count=1&&
    CALCULATE(DISTINCTCOUNT('Table'[Year]),
FILTER(ALL('Table'),'Table'[Group]=EARLIER('Table'[Group])&&'Table'[support]="yes"&&'Table'[Year]=_yearcurrent))=1,"New",
    _count=BLANK(),"Former&Non-Purchasing",
    _count>=1&&_count<=2&&
CALCULATE(DISTINCTCOUNT('Table'[Year]),
FILTER(ALL('Table'),'Table'[Group]=EARLIER('Table'[Group])&&'Table'[support]="yes"&&'Table'[Year]=_yearcurrent))=0,"transient")

2. Result:

vyangliumsft_1-1694052755356.png

 

 

Best Regards,

Liu Yang

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

1 REPLY 1
Anonymous
Not applicable

Hi  @JB17 ,

 

I created some data:

vyangliumsft_0-1694052755352.png

 

Here are the steps you can follow:

1. Create calculated column.

Flag =
var _yearcurrent=YEAR(TODAY())
var _count=
CALCULATE(DISTINCTCOUNT('Table'[Year]),
FILTER(ALL('Table'),'Table'[Group]=EARLIER('Table'[Group])&&'Table'[support]="yes"&&'Table'[Year]>=_yearcurrent-4&&'Table'[Year]<=_yearcurrent))
return
SWITCH(
    TRUE(),
    _count=5,"Loyal",
    _count>=3&&_count<=4&&
    CALCULATE(DISTINCTCOUNT('Table'[Year]),
FILTER(ALL('Table'),'Table'[Group]=EARLIER('Table'[Group])&&'Table'[support]="yes"&&'Table'[Year]=_yearcurrent))=0,"Potentially Loyal",
    _count=1&&
    CALCULATE(DISTINCTCOUNT('Table'[Year]),
FILTER(ALL('Table'),'Table'[Group]=EARLIER('Table'[Group])&&'Table'[support]="yes"&&'Table'[Year]=_yearcurrent))=1,"New",
    _count=BLANK(),"Former&Non-Purchasing",
    _count>=1&&_count<=2&&
CALCULATE(DISTINCTCOUNT('Table'[Year]),
FILTER(ALL('Table'),'Table'[Group]=EARLIER('Table'[Group])&&'Table'[support]="yes"&&'Table'[Year]=_yearcurrent))=0,"transient")

2. Result:

vyangliumsft_1-1694052755356.png

 

 

Best Regards,

Liu Yang

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.