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
kressb
Helper V
Helper V

Amount for Same Day Last Year

I have a 3 tables set up like so:

Tables.png

 

I want to make a table that shows the Amount for the Same Day Last Year, ex:

AmtLY.png

I have tried:

AmountPY = Calculate(sum(DataTable[Amount]),Sameperiodlastyear(DateDimension[Date]))
The error states: Function Sameperiodlastyear expects a contiguous selection when the date column comes from a table on the 1-side of a bi-directional relationship. ??

 

AmountPY= Calculate(sum(DataTable[Amount]),

                                    Filter(DateDimension,

                                             Date(
                                              Year(DateDimension[Date]-1),
                                               Month(DateDimension[Date]),
                                                Day(DateDimension[Date])
                                                       )))
Returns same # as Current Year

What am I missing?
5 REPLIES 5
kressb
Helper V
Helper V

@Jihwan_Kim @Ashish_Mathur 
I had a Many:Many Relationship between the DateDimension and a different table.

I changed the filtering from both to Single DateDimension filters DifferentTable.

That seems to have fixed the issue.

I am completely self taught and do not understand how this relationship created such an issue.

Would anyone be willing to post some articles of learning?
All i know is to avoid Many:Many as much as possible. TYIA.

Jihwan_Kim
Super User
Super User

Hi, @kressb 

I have tried your first calculated measure and it worked.

I hope your dim date table is continuous and marked as a date table.

 

thank you.

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


@Jihwan_Kim it is marked a date table.

What is meant by "continuous"?
DateDimension[Date] is calculated =Calendar(Date(2019,07,01),Date(2022,12,31))

Ashish_Mathur
Super User
Super User

Hi,

Both relationships should be Many to One and Single.  Drag Date from the Date Table.  Write these measures:

Total = sum(data[amount])

Total in SPLY = calculate([Total],sameperiodlastyear(calendar[date]))

If this does not work, then share the link from where i can download your PBI file.  


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur 
Unfortunately cannot share file.
I pulled out the 3 tables in question (there are 42 tables in this build) and it works fine on it's own.

Could an appended query cause any issue with this?
Each year of Amounts is in a separate table (DataTable_2020, DataTable_2021), which I appended as a new query - DataTable_ALL

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.