Forum Discussion
Measure to sum another measure problem
- 6 years ago
Hi ,
Under Modeling , New Table put this in:
Tb_Products_w_no_Sales = SUMMARIZECOLUMNS(Table1[Date ],
(Filter (SUMMARIZECOLUMNS(Table1[Date ],Table1[Product],"ZERO_S",IF(SUMX(Table1,Table1[Sales])=0,0,1)),[ZERO_S]=0)),"Products_w_no_Sales",DISTINCTCOUNT(Table1[Product]))*overall idea, ZERO_S will give 0 for rows of products with no sales, and after do a distinct count on product
where Table1 is your data.This should be what you want. i believe
is not correct, it should be 3. but let me know.02/01/2019 2 If you need a 0 on the missing dates, link it to a date table or left join it.Regards - 6 years ago
Hi johnfa ,
We can create a calcualted column and new a measure based on it.
per product = CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', 'Table'[Date ] = EARLIER ( 'Table'[Date ] ) && 'Table'[Product] = EARLIER ( 'Table'[Product] ) ) )Measure = CALCULATE(DISTINCTCOUNT('Table'[Product]),FILTER('Table','Table'[per product] = 0))
Thanks for taking the time to explain it fully thats really helpful. Being new to DAX it is certainly easier to follow if every step is broken down explicitly into a separate table although obviously a bit long winded. It is frustrating that you cant refer to columns created in the inner table in the outer table in the same block ie "Products_w_no_Sales" - I am used to working with SQL where you can easily create aliases for datasets and columns and refer to them later. Would it be possible to assign the inner table to a variable and then use that later to refer to all the columns we want ?
Hi, Jo
afaik, its is not yet possible to declare global var in DAX:
However for improve readaiblity, its possible to have local var:
Tb_Products_w_no_Sales =
Var
InnerTable= SUMMARIZECOLUMNS(Table1[Date ],Table1[Product],"ZERO_S",IF(SUMX(Table1,Table1[Sales])=0,0,1)
Return
SUMMARIZECOLUMNS(Table1[Date ],
(Filter (InnerTable),[ZERO_S]=0)),
"Products_w_no_Sales",
DISTINCTCOUNT(Table1[Product])