0
votes

I am trying to figure out the DAX to create a new measure in an SSAS Tabular data model. An example of what I am trying to do is more easily shown than described. My SSAS Tabular dataset produces the following table. Cols A and B are from the stores table, Col C is a measure from the Sales table, Col D is a measure from the Products table, and Col E is C/D. This all works fine. Data has been mocked up in Excel to protect the innocent, but it is working in Power BI.

This is working

What I would like to do is add a new measure which calculates the Sales/Product at the state level and have that measure show for each store in that state, as shown below

This is what I want

Presumably I have to iterate over all rows and calculate the total sales/state and total products sold/state and divide those 2 to get the answer, but can't work out the DAX to get there. I have tried numerous combinations of calculate(sumx(...),filter(all(...),... to no avail.

I think it might be something like this (?): StateTotalsByProductAndDate:= ADDCOLUMNS ( CROSSJOIN ( VALUES ( 'Product'[Name] ), VALUES ( 'Date'[Date]), VALUES ( 'Stores'[State]) ), "Amt", [Sales Amount] )Jim