D A X: Formula to show all products in all months

tiawy

New Member
Joined
Nov 30, 2014
Messages
11
Hi guys

I am new to DAX and I am having a bit of trouble getting a dax formula to show all products even though they haven't been sold for a particular month..


My data consists of one table and looks like this. (Month is a calculated column)
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Country[/TD]
[TD]Product[/TD]
[TD]Quantity[/TD]
[TD]Date[/TD]
[TD]Month[/TD]
[/TR]
[TR]
[TD]GB[/TD]
[TD]P1[/TD]
[TD]4[/TD]
[TD]2014-1-1[/TD]
[TD]January[/TD]
[/TR]
[TR]
[TD]GB[/TD]
[TD]P2[/TD]
[TD]3[/TD]
[TD]2014-1-1[/TD]
[TD]January[/TD]
[/TR]
[TR]
[TD]GB[/TD]
[TD]P3[/TD]
[TD]2[/TD]
[TD]2014-2-1[/TD]
[TD]February[/TD]
[/TR]
[TR]
[TD]GB[/TD]
[TD]P1[/TD]
[TD]4[/TD]
[TD]2014-2-1[/TD]
[TD]February[/TD]
[/TR]
[TR]
[TD]CAN[/TD]
[TD]P1[/TD]
[TD]2[/TD]
[TD]2014-1-1[/TD]
[TD]January[/TD]
[/TR]
[TR]
[TD]CAN[/TD]
[TD]P4[/TD]
[TD]3[/TD]
[TD]2014-1-1[/TD]
[TD]January[/TD]
[/TR]
[TR]
[TD]CAN[/TD]
[TD]P1[/TD]
[TD]2[/TD]
[TD]2014-1-1[/TD]
[TD]February[/TD]
[/TR]
</tbody>[/TABLE]

I have made a calculated field called YTD that calculates year-to-date SUMS for the different products.
I also have made a calculated field called sum, that calculates the sum of products sold for the context specified in the PivotTable.


In the resulting PivotTable i get this result, if i for instance make a slicer on february:

February:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Country[/TD]
[TD]Product[/TD]
[TD]SUM[/TD]
[TD]YTD[/TD]
[/TR]
[TR]
[TD]GB[/TD]
[TD]P1[/TD]
[TD]4[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]GB[/TD]
[TD]P3[/TD]
[TD]2[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]CAN[/TD]
[TD]P1[/TD]
[TD]2[/TD]
[TD]4[/TD]
[/TR]
</tbody>[/TABLE]


However what i want is this (I have highlighted what is different):

February:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Country[/TD]
[TD]Product[/TD]
[TD]SUM[/TD]
[TD]YTD[/TD]
[/TR]
[TR]
[TD]GB[/TD]
[TD]P1[/TD]
[TD]4[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]GB[/TD]
[TD]P2[/TD]
[TD]0[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]GB[/TD]
[TD]P3[/TD]
[TD]2[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]CAN[/TD]
[TD]P1[/TD]
[TD]2[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]CAN[/TD]
[TD]P4[/TD]
[TD]0[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]



So when I have made a slicer on dates, and I choose for instance february it shows only the products sold in february. But i want i to show all the products that has YTD>0, and just put a 0 in the SUM for the products that hasen't been sold that month.



I know i could solve this by inserting rows in the data source with quantity 0 for the products that hasen't been sold in a month. But this seems like a bad hack - and since there a lots and lots of products this would result in many unnecessary rows...


I know how to solve it in SQL, but that is not an option here..I have tried to google it but havent found a solution to this in DAX.

Thank you for your help
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Do you have product and geography lookup tables? You kinda want that... and then you put fields from THOSE tables on your pivot and will likely get what you want....
 
Upvote 0
Thank you for your response.
The problem is however that there is no lookup tables. There is only one table - the one shown above.

That is what makes it challenging!
 
Upvote 0
While not everything you needed this does most of it except when there is no product value for a month and country. If you add the County and Product to rows with Tabular layout and then add the following measures to the values. You can then add a slicer for Month


YTD Sales:=CALCULATE(SUM(Sheet1[Quantity]),ALL(Sheet1[Month]))
Month Sales:=TOTALMTD(SUM(Sheet1[Quantity]),Sheet1[Date])
 
Upvote 0
I don't think this is an ALL() problem.

Actually... it's kinda weird. Since you have a YTD measure, it should return a value for P2 in Feb... I'm actually wondering if that measure is working correctly. If you are using the builtin DATESYTD or similiar, those require a "real" date table, wonder if that's what is wrong?
 
Upvote 0

Forum statistics

Threads
1,224,056
Messages
6,176,118
Members
452,707
Latest member
elbiar

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