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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AliSharifi
Helper I
Helper I

Comparing this year and last year measure on a bar chart

Hi,

 

I'm going to show a meaure values of this year and last year on a bar chart. I created a new measure in PowerBI Desktop with this formula:

 

formula.PNG

The problem is when I use a Time Slicer and select a year, The calculated measure be disapeared and It sounds the last year data getting filter out from the dataset:

oneyear.PNG

 

I can see the OrderQuantityLY just when more than 1 year is selected:

 

2 years.PNG

Any suggestion?

 

Thanks,

Ali

 

 

2 ACCEPTED SOLUTIONS
Sean
Community Champion
Community Champion

@AliSharifi Create a clustered column chart

 

In the Axis - enter CalendarMonth (this should be a field from the DimDate table that represents just the months)

 

In the Legend - enter CalendarYear (again from the DimDate table the field that represents just the years)

 

this field CalendarYear should be the same field you use for the Slicer


In the Value - enter this measure OrderQuantity = SUM(FactInternetSales[OrderQuantity])

This will create a chart that will show 12 columns - overall totals for Jan thru Dec for all years

 

Then select as many years in the slicer as you wish - you will get that many columns for each month

 

this works with line charts too and you can select any years to compare not just consecutive

 

View solution in original post

I'm glad it is working.  

 

A couple of points.

  1. You can join on integers, it is just that you can't use the inbuilt time intelligence (something I didn't know until @greggyb mentioned it here).  You can of course write a formula using FILTER like I showed earlier.  I agree this should be changed and I am sure it will.
  2. In Power Pivot/Power BI, data type is not very important because Power Pivot manages the compression so well during data load using Run Length Encoding, Dictionary Encoding and Value Encoding.  So the byte size of the data type is less important.


* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

37 REPLIES 37

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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