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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Charan_Loya
New Member

Help with Year over Year comparison

Hello Everyone,

 

I apologize if I am asking a question that was already answered, I did search the prior requests before posting this question.

 

I am trying to understand the best way to show Year over Year comparison, the problem that I encounter is that the counts for the prior year is less than the actual value because things that happened in the prior year may not have happened in the current year and those counts are excluded in the calculation.

 

Here's an example: I am trying to show patient visits data for current year (Fiscal Year 2025) and compare the counts with prior year (Fiscal Year 2024), let's say Doctor A has seen 2 disease sites GI and lung patients in Fiscal Year 2024, but has only seen lung patients in Fiscal Year 2025, so when I look for Doctor A's counts I only see lung patient counts for both years, how do I make sure I get all the counts for Fiscal Year 2024 (both GI and Lung patients). 

 

I have tried several DAX functions including sameperiodlastyear, Paralellperiod, DATEADD, SelectedValue etc., but I am not getting the result I expect to see. Any help will be greatly appreciated.

 

P.S: I have filters (slicers) for Fiscal Year, Doctor and Disease site (and other slicers), so when I select Fiscal Year = 2025 and Doctor = A, Disease Site Filters down to only Lung, which is why we are missing GI counts for Fiscal year 2024. 

 

Hope my question is clear.

 

Thanks,

Charan

2 ACCEPTED SOLUTIONS
Kaviraj11
Super User
Super User

Hi,

 

Here’s a step-by-step approach to achieve this:

  1. Create a Measure for Total Visits: First, create a measure to calculate the total patient visits without any filters applied.

    Total Visits = COUNTROWS('PatientVisits')
  2. Create a Measure for Visits Last Year: Use the SAMEPERIODLASTYEAR function to calculate the visits for the same period last year.

    Visits Last Year = CALCULATE([Total Visits], SAMEPERIODLASTYEAR('Date'[Date]))
  3. Create a Measure for Visits with All Disease Sites: To ensure you get all counts for Fiscal Year 2024, regardless of the filters applied, use the ALL function to ignore the Disease Site filter.

    Visits Last Year All Sites = CALCULATE([Total Visits], SAMEPERIODLASTYEAR('Date'[Date]), ALL('PatientVisits'[DiseaseSite]))
  4. Combine Measures for Comparison: Now, create a measure to compare the current year’s visits with the previous year’s visits, including all disease sites.

    YOY Comparison = 
    IF(
        ISBLANK([Total Visits]),
        BLANK(),
        [Total Visits] - [Visits Last Year All Sites]
    )
     



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

Proud to be a Super User!





View solution in original post

Anonymous
Not applicable

Hi @Charan_Loya ,

 

@Kaviraj11 , thanks for your concern about this case. I tried to create a sample data myself based on this requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:

1\I assume there is a table(Table)

vbofengmsft_0-1728367740431.png

2\Add a new caculate table (DiseaseSiteTable) to separate and deduplicate all the disease locations from the original table.

DiseaseSiteTable = DISTINCT('Table'[Disease Site])

vbofengmsft_2-1728367857873.png

3\Relate Table and DiseaseSiteTable

vbofengmsft_3-1728367963032.png

4\Add a Matrix table

vbofengmsft_4-1728368070675.png

 

Best Regards,

Bof

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Charan_Loya ,

 

@Kaviraj11 , thanks for your concern about this case. I tried to create a sample data myself based on this requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:

1\I assume there is a table(Table)

vbofengmsft_0-1728367740431.png

2\Add a new caculate table (DiseaseSiteTable) to separate and deduplicate all the disease locations from the original table.

DiseaseSiteTable = DISTINCT('Table'[Disease Site])

vbofengmsft_2-1728367857873.png

3\Relate Table and DiseaseSiteTable

vbofengmsft_3-1728367963032.png

4\Add a Matrix table

vbofengmsft_4-1728368070675.png

 

Best Regards,

Bof

 

Thanks for looking into this and I apologize for the late response. I think I need to give you some more information on what I am looking to achieve.

 

  1. Disease site filter is one of the many filters I have in my dashboard, I also have other filters like Visit Location, Visit Type, Visit Specialty etc. that let's the users slice the data to their need. 
  2. I have used the New Card visual to show the selected year visit counts and added a reference label to compare it with prior year visit counts for the selected slicers. Below is a screenshot of how it looks.
  3. I also have a Matrix visual to show Current Year and Prior Year counts by specialty, I have added Year as column, Specialty as row and counts as values, the counts between the card and matrix for prior year (2024) does not match. This is what I am trying to fix. 

Charan_Loya_0-1729091514970.png

 

Charan_Loya_1-1729093172742.png

 

Thanks for all your help,

Charan

 

Kaviraj11
Super User
Super User

Hi,

 

Here’s a step-by-step approach to achieve this:

  1. Create a Measure for Total Visits: First, create a measure to calculate the total patient visits without any filters applied.

    Total Visits = COUNTROWS('PatientVisits')
  2. Create a Measure for Visits Last Year: Use the SAMEPERIODLASTYEAR function to calculate the visits for the same period last year.

    Visits Last Year = CALCULATE([Total Visits], SAMEPERIODLASTYEAR('Date'[Date]))
  3. Create a Measure for Visits with All Disease Sites: To ensure you get all counts for Fiscal Year 2024, regardless of the filters applied, use the ALL function to ignore the Disease Site filter.

    Visits Last Year All Sites = CALCULATE([Total Visits], SAMEPERIODLASTYEAR('Date'[Date]), ALL('PatientVisits'[DiseaseSite]))
  4. Combine Measures for Comparison: Now, create a measure to compare the current year’s visits with the previous year’s visits, including all disease sites.

    YOY Comparison = 
    IF(
        ISBLANK([Total Visits]),
        BLANK(),
        [Total Visits] - [Visits Last Year All Sites]
    )
     



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

Proud to be a Super User!





Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors