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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jptre8
New Member

Produce distinct count based on a year to year change condition being met

Hello all,

 

Its my first post here and I will start by thanking you all for your contributions. I have used response from this forum so often in the last couple years and I am thankful for the indirect support I have already receined. Now, I need help with a more specific issue that I cant resolve on my own.

 

I am trying to produce a KPI that essentialy count a number of distinct schools if the number of students has increased in the current year vs the last year.

 

I can do the year to year difference, but I am unable to used it as a condition for the distinct count.

 

My main attempt is to use measure #4 below to calculate the number of schools. The results I get is a blank column.

 

Fiscal YearSchools with more Students
20192020 
20202021 

 

I think it might be linked to the grain difference between the calculation of the diffence and the DISTINCTCOUNT() in measure #4, but I cant find a solution.

 

Would anyone have an idea that could help me? I am adding the measures and tables below.

 

Thank you!

 

Measures:

  1. Student Count Last Year = CALCULATE(SUMX('School_Table',[Number of Students]), FILTER(ALLSELECTED('Fiscal_Year_Table'),'Fiscal_Year_Table'[Fiscal_Year _Rank]=max('Fiscal_Year_Table'[Fiscal_Year_Rank])-1))+0
  2. Student Count This Year = CALCULATE(SUMX('School_Table',[Number of Students), FILTER(ALLSELECTED('Fiscal_Year_Table'),'Fiscal_Year_Table'[Fiscal_Year_Rank]=MAX('Fiscal_Year_Table'[Fiscal_Year_Rank])))
  3. YtYStudent CountDifference = [Student Count Last Year]-[Student Count This Year]
  4. Schools with more Students = CALCULATE(DISTINCTCOUNT(School_Table[School_ID]),FILTER([YtYStudent CountDifference]>0))

School_Table

School_IDNumber of StudentsFiscal_Year
110020192020
120020202021
220020192020
210020202021

 

Fiscal_Year_Table

Fiscal_Year_IDFiscal_YearFiscal_Year_Rank
1201920201
2202020212
3202120223

 

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @jptre8 - you can adjust the measure for "Schools with more Students" to correctly apply the filter.

 

Schools with more Students =
CALCULATE(
DISTINCTCOUNT('School_Table'[School_ID]),
FILTER(
VALUES('School_Table'[School_ID]),
[Student Count This Year] > [Student Count Last Year]
)
)

Hope it works.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
jptre8
New Member

@rajendraongole1 This solution worked like a charm! Thank you for taking the time to help.

rajendraongole1
Super User
Super User

Hi @jptre8 - you can adjust the measure for "Schools with more Students" to correctly apply the filter.

 

Schools with more Students =
CALCULATE(
DISTINCTCOUNT('School_Table'[School_ID]),
FILTER(
VALUES('School_Table'[School_ID]),
[Student Count This Year] > [Student Count Last Year]
)
)

Hope it works.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.