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
Anonymous
Not applicable

Calculating Last Year with SUMX and DateAdd

Hi Everyone,

 

This is a follow up from a previous post i made, however i hit a wall once again and after much research, need some help:

https://community.powerbi.com/t5/Desktop/Help-with-SUMX-Calculating-Total-Sales/m-p/501415#M234006

 

I am importing the below data into PBI using Power Query:

 

Dimesnion Attributes:

1. Date

2. Barcode 

3. Transaction Type

 

Measures:

1. Sales Price

2. Sales Units

 

Example of some records I import:

 

Ret Trans TypeStyle BarcodeDateSales PriceSales Units
S50533663730824/07/201889.162
S50533677195123/07/201852.011
S50533677195128/07/201844.581

 

Now that i have imported my data, what i must do is Multiply the Sales Price by the Sales Units: (Sales Price * Sales Units). The reason for this is to caclualte the Total Sales. However, i must use a SUMX as without the SUMX, the Grand Total would be incorrect from the multiplication of Price by Units.

  

 So, below are the Dax Statements which have been derived and work great:

 

Sales Price (SUM) = SUM(SALES[Sales Price])

Sales Units (SUM) = SUM(SALES[Sales Units])

Total Sales Retail (SUMX) =
SUMX(
VALUES(SALES[[Dim Product]].[Style Barcode]].[Style Barcode]].[MEMBER_CAPTION]]])
,([1b. Sales Units (SUM)] * [1a. Sales Price (SUM)])
)

 

 

Now the challenge i am having is: With the above measures, i am deriving the LY (Last Year) equivalent measures using the two DAX Statements below:

 

 

LY Sales Price = CALCULATE(SUM(SALES[Sales Price]),
                    DATEADD('CALENDAR'[Dim Date.Date],-364,Day))

LY Sales Units = CALCULATE(SUM(SALES[Sales Units]),
                    DATEADD('CALENDAR'[Dim Date.Date],-364,Day))

 

 

Everyhting above works as expected with no data issue 😄

 

However, when i try create the LY (Last Year) Equivalent for Total Sales Retail (SUMX) using the below DAX i get NO values returned in the result set.

 

 

Total Sales Retail (SUMX) = 
SUMX(
    VALUES(SALES[[Dim Product]].[Style Barcode]].[Style Barcode]].[MEMBER_CAPTION]]])
    ,([LY Sales Units] * [LY Sales Price])
) 

 

Any idea or help would be much appreciated.

 

Thank you

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Greg_Deckler,

 

I had managed to achieve the outcome i was looking for in Power BI through going back to the Drawing Board.

 

All my issues were resolved once i imported at a Transaction ID level, instead of my lowest level being Barcode, which is essentially Product ID.

 

I can explain in more detail, but that would be pointless now. With that said, thank you for all your input 🙂

View solution in original post

12 REPLIES 12

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.