Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
avalonds
Frequent Visitor

Alternative to ALL() and ALLSELECTED() to get cumulative total

I want to get a cumulative total from a virtual 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.

 

FYTD_SalesPercent of Variable Table= 
//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])



 

 

 

1 REPLY 1
v-huizhn-msft
Employee
Employee

Hi @avalonds,

The ALLSELECTED function gets the context that represents all rows and columns in the query, while keeping explicit filters and contexts other than row and column filters.  "I just want it to always take the total of all items# sales and not segregate it by brand." Brand and items are in a same table, right? If you want to ALLSELCTED keep filter for all items of sales, rather than brank, it's impossible.

Thanks,
Angelia

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.