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

Relationship Works for Total Sales This Year, Breaks for Total Sales Last Year

I have a date table, a store table, and a sales table. I have relationships set up between the date table and sales table and the stores table and the sales table. In the table visual I am trying to create, I am trying to look at the total sales for each store on a single day this year and compare it to 364 days ago. 

 

I've filtered the report page for a single day and added a table with a column for stores and two additional columns for measures.  My measure for sales this year is CALCULATE(SUM(TransactionAmount)) and my measure for sales last year is  CALCULATE(SUM(TransactionAmount), DATEADD(Dates[Date], -364, DAYS). The column for the current year's measure works fine. However, the column for last year's sales measure returns Blank for every store. However, the total for last year's sales across all stores is correct.

 

Thank you in advance. 

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @lbamburoski ,

 

Try this measure:

last_364 = 
VAR CurrentDATE =
    MAX ( 'Calendar'[Date] )

RETURN
    (
        CALCULATE (
            SUM ( SALES[sales]),
            FILTER (
                ALL ( 'Calendar' ),
                'Calendar'[Date]=CurrentDATE-364
            )
        )
    )

test_last_364.PNGtest_last_364_2.PNG

 

Best Regards,
Liang
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-lianl-msft
Community Support
Community Support

Hi @lbamburoski ,

 

Try this measure:

last_364 = 
VAR CurrentDATE =
    MAX ( 'Calendar'[Date] )

RETURN
    (
        CALCULATE (
            SUM ( SALES[sales]),
            FILTER (
                ALL ( 'Calendar' ),
                'Calendar'[Date]=CurrentDATE-364
            )
        )
    )

test_last_364.PNGtest_last_364_2.PNG

 

Best Regards,
Liang
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

@lbamburoski , is "dates" is marked as date table. Also Are you filter and axis/row/grouping of data from date table, whenever needed. My webinar link you can get pbix to download.

 

Please Watch/Like/Share My webinar on Time Intelligence: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...
My Youtube Tips at: https://www.youtube.com/playlist?list=PLPaNVDMhUXGYrm5rm6ME6rjzKGSvT9Jmy

Appreciate your Kudos.

mahoneypat
Employee
Employee

Try DATEADD(Dates[Date],-1,YEAR) instead.  Also, you probably don't need the CALCULATE() around your current year measure.

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.