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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
rahulvyas
Frequent Visitor

SAMEPERIOD LAST YEAR BY CATEGORY

I have two Measure none of them work when I try to use them with the category to get Last Year's Cost vs. Current Year Comparison. I need to show the comparison between the categories. 

Formula 1
LY COST =
CALCULATE( [$CostBeforeTax] , CALCULATETABLE(SAMEPERIODLASTYEAR('Date'[SnapshotDate]), DATESYTD('Date'[SnapshotDate])))
Alternate Formula 2 
LAST YTD SALES = CALCULATE(SUM(AzureBilling[CostBeforeTax]), DATESYTD(DATEADD('Date'[SnapshotDate],-1, YEAR), "10-31"))
 
If I use Fiscal Year or Snapshot date then my visuals are working  but it doesn't work if I am trying to compare categories or product 
Here is the example 
rahulvyas_0-1705948631299.png

 

rahulvyas_1-1705949023561.png

 


DataModel Snippet 
There are only two table 
Date[SnapshotDate] 1-Many relationships with Cost Table [Billingdate] --Single Cross Filter Directional 
When we use Both Cross Filter Directional it gives an error since SMPLY AND DateADD both don't work with the bidirectional relationship. 






1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@rahulvyas , You should always use Date table in visual, measure and slicers . Make sure date table has all dates, marked as date table and period from date table is used in visual and slicers

 

example

 

LY COST =
CALCULATE( [$CostBeforeTax] ,DATESYTD(DATEADD('Date'[SnapshotDate],-1, Year))))

 

LY COST =
CALCULATE( [$CostBeforeTax] ,(DATEADD('Date'[SnapshotDate],-1, Year)))

 

 

LYTD COST =
CALCULATE( [$CostBeforeTax] ,DATESYTD(DATEADD('Date'[SnapshotDate],-1, Year), "10/31"))


Alternate Formula 2
LAST YTD SALES = CALCULATE(SUM(AzureBilling[CostBeforeTax]), DATESYTD(DATEADD('Date'[SnapshotDate],-1, YEAR), "10/31"))

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @rahulvyas ,

Like @amitchandak  said, your two measures are written based on time, that should use Date table in visual

I have created a simple sample, please refer to.

Measure:

Measure = CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[date]=SELECTEDVALUE('Table'[date])))

vrongtiepmsft_0-1705979788318.png

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

amitchandak
Super User
Super User

@rahulvyas , You should always use Date table in visual, measure and slicers . Make sure date table has all dates, marked as date table and period from date table is used in visual and slicers

 

example

 

LY COST =
CALCULATE( [$CostBeforeTax] ,DATESYTD(DATEADD('Date'[SnapshotDate],-1, Year))))

 

LY COST =
CALCULATE( [$CostBeforeTax] ,(DATEADD('Date'[SnapshotDate],-1, Year)))

 

 

LYTD COST =
CALCULATE( [$CostBeforeTax] ,DATESYTD(DATEADD('Date'[SnapshotDate],-1, Year), "10/31"))


Alternate Formula 2
LAST YTD SALES = CALCULATE(SUM(AzureBilling[CostBeforeTax]), DATESYTD(DATEADD('Date'[SnapshotDate],-1, YEAR), "10/31"))

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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