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
Imagauthamam
Helper II
Helper II

Need Help in LY and TY Measure based on a slicer

Hi Community,

I'm a beginner in Power BI. Need help in 2 measure calculations.

I'm just showing LY and TY comparison. This works fine independently.

But when we put a Year slicer, this doesnot work as expected.

Below, are my measure calculations:

Total Records LY =
Var Year = YEAR(MAX([activity_date]))-1
return CALCULATE(COUNTROWS('Fact'),'Calendar'[Year]=Year)
Total Records TY =
Var Year = YEAR(MAX([activity_date]))
return CALCULATE(COUNTROWS('Fact'),'Calendar'[Year]=Year)
 
Below are my requirements:
If we select 2023 in Year slicer, the CY measure should give the data for entire 2023 and LY measure should give the data for entire 2022. From the below screenshot, there is no data after June for LY measure even though data is available for entire 2022
Similarly, If I select 2022 in Year slicer, CY should give 2022 data and LY should give 2021 data and all the months  should be visible in X axis

 

Screenshot 2023-06-06 140958.jpg

1 ACCEPTED SOLUTION

@Dhairya I tried this but it was not working for me.

Meanwhile I have modified the measure to get the required output

 

add a Year Slicer, make it single select (from date dimension)
add a chart with Month (from date dimension) on x and 2 measure (Total Records , Total Records LY)

Total Records = COUNTROWS('Fact')
Total Records LY = CALCULATE([Total Records], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )

View solution in original post

4 REPLIES 4
Imagauthamam
Helper II
Helper II

Hi @Dhairya 

Thanks for the reply. But I'm getting the error:

Screenshot 2023-06-06 155725.jpg

Have you created a seperate date table named Calendar?
If yes then  the above year is for dataytype of that Calendar'date' column,
In PREVIOUSYEAR function you have to pass field having 'date' datatype. 

@Dhairya I tried this but it was not working for me.

Meanwhile I have modified the measure to get the required output

 

add a Year Slicer, make it single select (from date dimension)
add a chart with Month (from date dimension) on x and 2 measure (Total Records , Total Records LY)

Total Records = COUNTROWS('Fact')
Total Records LY = CALCULATE([Total Records], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )

Dhairya
Super User
Super User

Can you please try below measure to calculate previous year data

TOTAL RECORDS LY = CALCULATE(COUNTROWS('Fact'), PREVIOUSYEAR('Calendar'[Year]))

Please mark my solution as accepted if it worked for you!

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.