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
otter
Frequent Visitor

Same period last year not working while filter both ways

Hello,

 

Currently I have a fact table that consists of Sales Date, Delivery Date and Sales $

Sales DateDelivery DateSales $

 

I have 2 filter tables that has calendar to filter Sales Date and Delivery Date:

Sales Date
Delivery Date

 

I used relationship filtering both way between 3 tables, because I want Sales Date to also filter Delivery Date

 

I want to then have Same Period Last Year based on Sales Date:

Sales $ LY = CALCULATE(SUM('Fact table'[Sales $]), SAMEPERIODLASTYEAR('Sales calendar'[Sales Date]))

 However it has thrown error: Function 'SAMEPERIODLASTYEAR' expects a contiguous selection.

 

I tried to bypass by putting:

Sales $ LY = IF(SELECTEDVALUE('Sales calendar'[Sales Date]) = BLANK(), BLANK(),
CALCULATE(SUM('Fact table'[Sales $]), SAMEPERIODLASTYEAR('Sales calendar'[Sales Date])))

It didn't work.

 

Is there any idea how I can overcome this?

 

Thank you beforehands!

 

BR,

Otter

2 REPLIES 2
amitchandak
Super User
Super User

@otter , You need to have a date table join both dates with the date of the date table(I think sales calendar). One join will be inactive. Make sure it marked as date table.

 

Assume delivery join is inactive

 

Then LY can be

Sales $ LY = CALCULATE(SUM('Fact table'[Sales $]), SAMEPERIODLASTYEAR('Date'[Date]))

 

 

Sales $ LY delivery = CALCULATE(CALCULATE(SUM('Fact table'[Sales $]),userelationship('Date'[Date], 'Fact table'[delivery Date] )), SAMEPERIODLASTYEAR('Date'[Date]))

 

 

Other options are

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR('Date'[Date]))

 

 

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.

Hello,

 

My relationships are like this:

Fact table <> Sales calendar (two way relationship)

Fact table <> Delivery calendar (two way relationship)

 

None of the relationships are inactive.

 

I want that I can use Date filters for either Sales Date and Delivery Date as separate Filters. I.e. when I choose a Sales Date, it will show different Delivery Dates in the other filter and vice versa.

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.