I want to get a cumulative total from a variable table but using the code below limits my use because of allselected. The moment I add more attributes to the table, the cumulative total changes but I don’t want it to do that.
I have the following data tables:
Dim Date:
- Calendar date (key)
- FY
Dim Product:
- Order # (key)
- Item #
- Brand (one brand could have several item #s under it)
Fact Sales:
- Calendar date (key)
- Order # (key)
- Units
- Sales
I also have the following measures:
FYTD Sales - Gives me the 2018 fiscal year to date sales of the max date selected
PYTD Sales - Gives me the corresponding prior year to date sales
FYTD ASP - Gives me the 2018 average selling price (Sales / Units). If units is 0 or sales is -ve (due to a credit), ASP will be zero.
PYTD ASP - Gives me the corresponding period average selling price (Sales / Units). If units is 0 or sales is -ve (due to a credit), ASP will be zero.
Issue:
I have a table with rows that shows the item#. My goal is to get % of sales (sales / Total sales) for each item# whose FYTD_ASP and PYTD_ASP <> 0. This measure would be shown on the table. The code below is what I have so far.
While the code works on item#, the moment I add another column (such as brand) with my item# still in the first column of the table, the ALLSELECTED messes up the FYTD_TotSales by taking the cumulative brand total sales for a group of items within that brand. I don’t want it to do that. I just want it to always take the total of all items# sales and not segregate it by brand.
PercentSalesofVirtualtable =
//1. Create a filtered table of products without all the new, discontinued and credit/other products (the FYTD_ASP and PYTD_ASP <>0, filters for these products)Var FilteredItemTable = FILTER(ALLSELECTED(‘Dim-Product’[Item#]), [FYTD_ASP$]<>0 && [PYTD_ASP]<>0)
//2. Compute FYTD Total Sales from filtered table required
Var FYTD_TotSales = CALCULATE([FYTD_Sales],FilteredItemTable)//3. Compute % of Sales
Return SUMX(ADDCOLUMNS(VALUES(‘Dim-Product’[Item#]), “SalesPecent”,
IF( ISBLANK([PYTD_ASP]) || ISBLANK([FYTD_ASP]), 0, [FYTD_Sales] / FYTD_TotSales)),
[SalesPercent])