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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
rmaxfield
Frequent Visitor

DAX Formula to track year to year

I am new to using DAX. I want to get the retention rate of students (identified with StuID) who return from one year to the next year, along with the number of students who do not return. To track a specific cohort, I need to use "Curr enr" codes F1 or F2 in year one, but the student will be code C during their second, third, and fourth year, etc. It needs to be a distinct count because there can be multiple StuID records within one Year. Could someone help me with a formula that will track students from one year to the next and help me find a retention rate?

 

Screen Shot 2023-04-28 at 10.47.43 AM.png

 

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @rmaxfield ,

I created some data:

vyangliumsft_0-1682993745506.png

 

Here are the steps you can follow:

1. Create measure.

Rank =
RANKX(
    ALL('Table'),CALCULATE(SUM('Table'[Year])),,ASC,Dense)
Measure =
SWITCH(
    TRUE(),
'Table'[Rank]=MINX(ALL('Table'),[Rank]),
CALCULATE(
    DISTINCTCOUNT('Table'[StuID]),
    FILTER(ALL('Table'),
   'Table'[Rank]=MINX(ALL('Table'),[Rank])&&OR('Table'[Current]="F1",'Table'[Current]="F2")))
,
'Table'[Rank]>=MINX(ALL('Table'),[Rank])+1&&'Table'[Rank]<=MINX(ALL('Table'),[Rank])+3,
CALCULATE(
    DISTINCTCOUNT('Table'[StuID]),
    FILTER(ALL('Table'),
   'Table'[Rank]>=MINX(ALL('Table'),[Rank])+1&&'Table'[Rank]<=MINX(ALL('Table'),[Rank])+3&&'Table'[Current]="C"&&'Table'[Year]=MAX('Table'[Year]))))

2. Result:

vyangliumsft_1-1682993745509.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

Hello, thank you so much for your data suggestion. Would you please explain what the second Measure (using SWITCH) will calculate for me in this dataset?


Also, I find no error in my formula, but my Measure is coming out blank.

Screen Shot 2023-05-02 at 10.31.09 AM.png

 

Screen Shot 2023-05-02 at 10.31.12 AM.png

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors