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
Jmenas
Advocate III
Advocate III

DAX - Last Year Week Vs This Year Week to date - Rolling dates

Hi all,

 

I have an issue with the Rolling total from last year vs this year. I need to create a measure that calculates the following:

YTD Shipments / (LastYear(YTD shipments)/LastYear(Shipments)

This is being of an issue, mainly because the date of the data is the first Monday of each week, that means I have data from week to week. That is messing up when I use Dateadd functions. 

 

The YearToDate calculations are working fine the problem is last year running total. The important thing is no just the total index (formula above) but that it can be display and filter in a table or other visuals. 

 

Here is what I have done so far: 

ShipmentsLYTD =
IF (
    HASONEVALUE ( 'TableShipments'[Time] ),
    CALCULATE (
        SUM ( 'TableShipment'[Shipments] ),
        SAMEPERIODLASTYEAR ( 'TableShipment'[Time] )
    ),
    SUMX (
        SUMMARIZE (
            'TableShipment',
            'TableShipment'[Time],
            'TableShipment'[Country],
            "LYTD", CALCULATE (
                SUM ( 'TableShipment'[Shipments] ),
                SAMEPERIODLASTYEAR ( DATESYTD ( 'TableShipment'[Time] ) )
            )
        ),
        [LYTD]
    )
)

For the Last Year calculation I have:

TransLY = 
         IF(HASONEVALUE('TableShipments'[Time]),
         CALCULATE(
	        SUM('TableShipments'[Shipments]),
                      PREVIOUSYEAR('TableShipments'[Time])
            ),
        CALCULATE(
            SUM('TableShipments'[Shipments]),
            'TableShipments'[LY] = TRUE()
            )
        )

(updated) The LY calculation is like this:

LY = If(YEAR('TableShipments'[Time]) = YEAR(MAX('TableShipments'[Time]))-1,TRUE())

 

 

What I expect is something like the index in the last part of the screenshot. 
The data is something like this

2019-05-22 10_45_49-SEAPP.xlsx - Excel.png

 

 

Thanks in advance.

 

FYI: @thschr 

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

@Jmenas ,

 

YTD Shipments / (LastYear(YTD shipments)/LastYear(Shipments)

Could you explain more about the three columns/measures above? In addtion, in the Last Year calculation you provided, you use 

'TableShipments'[LY] = TRUE()

But where is the column [LY] in the sample data? Could you also share the expected result for further analysis?

 

Community Support Team _ Jimmy Tao

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

Hi @v-yuta-msft ,

 

Thanks, I updated the task with what you mentioned. 

 

Let me know you need more info. 
Best,
J.

 

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.