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

LY YTD repeated issue

I'm trying to get carts shipped YTD last year. I've tried each of the below without success. They either return a blank or the sum or last year or the total sum. 

 

1. LY YTD =
VAR DataMaxDate =
            CALCULATE ( MAX ( table_name[shipdate] ), ALL (table_name) )
RETURN
        CALCULATE (
            [YTD Carts],
           SAMEPERIODLASTYEAR (
           INTERSECT (
           VALUES ( table_name[shipdate] ),
          DATESBETWEEN ( table_name[shipdate], BLANK (), DataMaxDate )
                 )
         )
)

 

2. LY YTD = CALCULATE(
                                  SUM(
                                        table_name[Carts]),
                                         DATEADD(table_name[shipdate],-1,YEAR

      )

)

 

3. LY YTD = CALCULATE (
                              SUM (

                                      table_name[Carts] ),
                                      FILTER (
                                      table_name,
                                      YEAR ( table_name[shipdate] ) = YEAR ( TODAY () )-1
                                      && DAY ( table_name[shipdate] ) <= YEAR(DAY(TODAY()

                  )

           -1)
      )
)

 

 

Returns

1. blank

2. sum of LY 

3. inexplicably large number

 

New to DAX as you'll quickly see if you look at my recent posts. What am I missing? 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @KevinCP,

 

This may work if you have a relationship between the two tables and a [Dim_date] table since you may have multi shipments in the same day:

 

Create a Measuses:

1.Total Carts = SUM (table_name[Carts])

2.Total Carts LY = CALCULATE ([Toatal Carts], SAMEPERIODLASTYEAR(Dim_date[date]))

 

Hope help you

Regards

@Anonymous

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @KevinCP,

 

This may work if you have a relationship between the two tables and a [Dim_date] table since you may have multi shipments in the same day:

 

Create a Measuses:

1.Total Carts = SUM (table_name[Carts])

2.Total Carts LY = CALCULATE ([Toatal Carts], SAMEPERIODLASTYEAR(Dim_date[date]))

 

Hope help you

Regards

@Anonymous

 

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.