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
CJANE
Helper I
Helper I

Prior Year to Date - No Date Table

I am trying to create an expression to show total sales for prior YTD.  My Sales and Date are in the same table.  I do not have a separate date table.  Is there an expression that will work for this scenario?

 

Table Name is Trades

 

Fields are Gross Amount and Trade Date

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @CJANE 

You can create a Measure like the following.

 

LYTD =

var year=YEAR(MAX(Trades[Trade Date]))-1

return CALCULATE(SUM(Trades[Gross Amount]), FILTER(ALL(Trades),Trades[Trade Date]>=DATE(year,1,1)&&Trades[Trade Date]<=MAX(Trades[Trade Date])))

 

The result looks like this:

v-cazheng-msft_0-1616753647415.png

 

For more details, you can refer the attached pbix.

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

3 REPLIES 3
v-cazheng-msft
Community Support
Community Support

Hi @CJANE 

You can create a Measure like the following.

 

LYTD =

var year=YEAR(MAX(Trades[Trade Date]))-1

return CALCULATE(SUM(Trades[Gross Amount]), FILTER(ALL(Trades),Trades[Trade Date]>=DATE(year,1,1)&&Trades[Trade Date]<=MAX(Trades[Trade Date])))

 

The result looks like this:

v-cazheng-msft_0-1616753647415.png

 

For more details, you can refer the attached pbix.

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

You should not write any time intelligence function without a date table. The reason is that the time intelligence functions rely on a complete list of all days in the table to work. You can use the inbuilt date table if you like. Simply refer to it in locations where you must specify the date column, ie SAMEPERIODLASTYEAR(Trades[Date].[Date]). Note the extra .[Date]



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

@CJANE 

 

Try any of the following 2 formulas:

LYTD = CALCULATE(SUM(Trades[Gross Amount]), SAMEPERIODLASTYEAR(Trades[Trade Date]))
LYTD = CALCULATE(SUM(Trades[Gross Amount]), DATEADD (Trades[Trade Date], -1, YEAR))

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.