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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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