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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
m1ngle
Frequent Visitor

How to calculate Last year values

Hey all - I have a graph that works great in every way except the legend displays as a date. 

tl;dr - can I display this graph with the year only as the legend without breaking the calculations.

m1ngle_0-1714624080682.png

Is there any way I can display JUST the year portion of the date? Here's what I did

The "Period" column that I'm using for the legend is just a year. I made it into a date column as so
Fulldate =  "01/01/"& 'Table'[Period]

I basically just stick an 01/01 on the front and tell Power BI to recognize as a date.

To get Last Years Financial FTE (the height of the column), I first calculate the value of the last period
LY = CALCULATE(SUM('Table'[value]),SAMEPERIODLASTYEAR('Table'[Fulldate]))

I calculate this year's value 
TY = CALCULATE(SUM('Table'[Value])) and subtract the

LYDiff = [TY] - [LY] to get the change.

This is all great. I just need the legend as a year only. When I use [Fulldate].[Year] or whatever, the calculation breaks and I get just the totals and not the difference. I'm attaching a dataset of toy data. I would love to have a power BI I could attach that would show you what I want, but when I try to recreate the calculations with this data I get a circular dependency error even though I'm using the exact same fields.

VehicleBrandValuePeriod
CarHonda382024
CarToyota1472024
CarFord2542024
TruckGMC802024
TruckDodge2532024
BikeSchwinn2942024
BikeHuffy832024
AirplaneCessna1482024
AirplaneBoeing122024
CarHonda1942025
CarToyota972025
CarFord2312025
TruckGMC832025
TruckDodge62025
BikeSchwinn1522025
BikeHuffy392025
AirplaneCessna592025
AirplaneBoeing1522025
CarHonda2912026
CarToyota1782026
CarFord2992026
TruckGMC1672026
TruckDodge1372026
BikeSchwinn2872026
BikeHuffy2782026
AirplaneCessna1182026
AirplaneBoeing502026
CarHonda2172027
CarToyota2582027
CarFord1882027
TruckGMC1192027
TruckDodge2462027
BikeSchwinn1262027
BikeHuffy2422027
AirplaneCessna2962027
AirplaneBoeing2212027
1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@m1ngle,

 

You're on the right track with the Fulldate column. In this example, I created Fulldate in Power Query (custom column; set the data type to Date):

 

Table.AddColumn(ChangeType, "Fulldate", each #date([Period], 1, 1))

 

This allows you to use the DAX function CALENDARAUTO to create a date table. There are various ways to create a date table. Here's a simple DAX calculated table. You can add other columns such as Quarter, Month, etc. After you create this table, mark it as a date table (right-click the table and select "Mark as date table").

 

DateTable = 
ADDCOLUMNS ( CALENDARAUTO (), "Year", YEAR ( [Date] ) )

 

Create a relationship between the tables:

 

DataInsights_0-1714654713744.png

 

Use DateTable[Year] in the legend.

 

Revise your measure as follows:

 

LY =
CALCULATE ( SUM ( 'Table'[value] ), SAMEPERIODLASTYEAR ( DateTable[Date] ) )

 





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
Khushidesai0109
Helper III
Helper III

First of all You've correctly calculated the difference between This Year's value and Last Year's value.

Now, coming to the issue of displaying only the year portion of the date in the legend without breaking the calculations, you can achieve this without using the Fulldate column. Instead, you can directly use the Period column and format it in the way you want.

Here's how you can modify your legend to display only the year:

  1. In your visual, instead of using [Fulldate] or [Fulldate].[Year], use [Period] directly.
  2. Format the [Period] column in the legend to display only the year portion.

To format the [Period] column:

  1. Go to the Data view in Power BI Desktop.
  2. Find the [Period] column.
  3. Click on the dropdown arrow next to the column name.
  4. Choose "Format" and select "Year" from the list of date formats.

    If this post helps, Please give thumbs up and please consider Accept as the solution to help the other members find it more quickly..

    Thank you!!



DataInsights
Super User
Super User

@m1ngle,

 

You're on the right track with the Fulldate column. In this example, I created Fulldate in Power Query (custom column; set the data type to Date):

 

Table.AddColumn(ChangeType, "Fulldate", each #date([Period], 1, 1))

 

This allows you to use the DAX function CALENDARAUTO to create a date table. There are various ways to create a date table. Here's a simple DAX calculated table. You can add other columns such as Quarter, Month, etc. After you create this table, mark it as a date table (right-click the table and select "Mark as date table").

 

DateTable = 
ADDCOLUMNS ( CALENDARAUTO (), "Year", YEAR ( [Date] ) )

 

Create a relationship between the tables:

 

DataInsights_0-1714654713744.png

 

Use DateTable[Year] in the legend.

 

Revise your measure as follows:

 

LY =
CALCULATE ( SUM ( 'Table'[value] ), SAMEPERIODLASTYEAR ( DateTable[Date] ) )

 





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

Proud to be a Super User!




Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.