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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
shds
Advocate I
Advocate I

How can I create a same time last year column in Query Editor?

In the Power BI Desktop Query Editor I created an Unpivoted table based on certain attributes (columns to rows) which gives me correct values in a separate column. 

 

What I would like to do is create another column called "LastYear" which takes the row's Datetime and looks up the Value of the same date last year.

 

The PARALLELPERIOD expression doesn't seem to be giving the right results and I cannot get it to work in a Custom Column.

 

Here's what I tried for a calculated column in Power BI Desktop:

LastYear = CALCULATE(SUM('Table1'[Value]); PARALLELPERIOD('Table1'[Datetime]; -1; year))

 

Putting this formula in a Custom Column in Query Editor it first tells me there are no syntax errors found, but once I try to insert the column then it keeps saying "Expressions.Error: The name 'CALCULATE' wasn't recognized. Make sure it's spelled correctly.'

 

What am I doing wrong?

1 ACCEPTED SOLUTION
mike_honey
Memorable Member
Memorable Member

The Query Editor does not use DAX syntax.  Instead it uses the "Power Query Formula Language", also called "M" or "PQL".

 

Here's the link to it's formula doco:

 

https://msdn.microsoft.com/library/mt253322?ui=en-US&rs=en-US&ad=US

 

For your scenario, I would try something like this in your Custom Column:

 

= Date.AddYears ( [Datetime] , -1 )

 

Then to use that to "Lookup" the previous value, I would use a Merge to the same query - it should show as Table1 (Current). In the Merge definition, if your Custom Column is callend Datetime -1Y, then I would choose that column in the top table and Datetime in the bottom Table1 (Current).

 

Then I would expand the Value column from the resulting NewColumn.  The Expand button will be in the table header row, just to the right of NewColumn.

View solution in original post

2 REPLIES 2
mike_honey
Memorable Member
Memorable Member

The Query Editor does not use DAX syntax.  Instead it uses the "Power Query Formula Language", also called "M" or "PQL".

 

Here's the link to it's formula doco:

 

https://msdn.microsoft.com/library/mt253322?ui=en-US&rs=en-US&ad=US

 

For your scenario, I would try something like this in your Custom Column:

 

= Date.AddYears ( [Datetime] , -1 )

 

Then to use that to "Lookup" the previous value, I would use a Merge to the same query - it should show as Table1 (Current). In the Merge definition, if your Custom Column is callend Datetime -1Y, then I would choose that column in the top table and Datetime in the bottom Table1 (Current).

 

Then I would expand the Value column from the resulting NewColumn.  The Expand button will be in the table header row, just to the right of NewColumn.

Thanks Mike, that pointed me in the right direction!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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