Latest Weeks Volume Issue with DAX

matratus34

Board Regular
Joined
Nov 21, 2013
Messages
76
Hi,
This might not be enough detail, but I have sales and volume data (t_volumes) linked to a calendar table (t_calendar) in Power Pivot.
The t_volumes data is at week, customer and product level.
There is also a t_product table linked to the T_volumes table, that contains all my product categories, unit of purchase etc

I'm trying to build a report that includes a column in a pivot for the latest weeks volumes - at different levels e.g Product, Catergory etc


If I hard code the lastest week into my DAX I get the correct results in my Pivot table (when pulling in Category out of my t_product table too).
But If I use a variable to look at the latest week it doesn't work (see below)

What I think is happening is that although there is volume for every week in data, there isn't always volume for every week and Category combination. If the code doesn't find any sales in the latest week for a Category then it brings back the volumes for that category for the latest week that it had sales in.


This code works:


HCLatestWeekVolumes:=CALCULATE(
SUM(t_volumes[Eaches]),
t_calendar[Long week] = 202522)


This code doesn't work

LatestWeekVolumes:=VAR LatestWeek = MAX(t_volumes[Long week])
RETURN
CALCULATE(
SUM(t_volumes[Eaches]),
t_calendar[Long week] = LatestWeek
)



In the data in the screenshot - taking Group 2 as an example - the Category had no sales in the latest week so left column is correct.
The right column (which uses the DAX with the variable brings in a volume of 200 which was the volume the Category had in the previous week.

I've played around with DAX containing the MAX function but I can't get it to work properly - can anyone help ? Thanks
 

Attachments

  • pp.png
    pp.png
    19.3 KB · Views: 4

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
what if you write it like this?
Do you have the correct relationships?

Excel Formula:
CALCULATE(
  SUM(t_volumes[Eaches]),
   t_calendar[Long week] = MAX(t_volumes[Long week])
 )
 
Upvote 0

Forum statistics

Threads
1,224,810
Messages
6,181,079
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top