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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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.

View solution in original post

2 REPLIES 2
v-rongtiep-msft
Community Support
Community Support

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.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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