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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.