So I thought I was starting to understand context transition, but I got thrown a curveball over the weekend.
I have a dataset that records sales, where each row is a single sale transaction. Columns include a customerid and product id that both connect out to dimension tables, but also includes various other items, such as number of units, sale price, unit cost etc.
From this I have a measure
basically adding up all the columns to give a profit. This has worked fine for me in general.
I've then created a measure that uses SWITCH( ), that iterates down the rows, and depending on the product type multiplies [Total Profit] by a rebate factor. This measure is where I got some surprising results, but you can see the same thing in this simple version of the measure (which you would never want to use in practice).
I have a dataset that records sales, where each row is a single sale transaction. Columns include a customerid and product id that both connect out to dimension tables, but also includes various other items, such as number of units, sale price, unit cost etc.
From this I have a measure
Code:
[Total Profit]:= SUM ( [Sales Price] ) + SUM ( [Unit Cost] ) + etc
basically adding up all the columns to give a profit. This has worked fine for me in general.
I've then created a measure that uses SWITCH( ), that iterates down the rows, and depending on the product type multiplies [Total Profit] by a rebate factor. This measure is where I got some surprising results, but you can see the same thing in this simple version of the measure (which you would never want to use in practice).
Code:
SUMX (
Sales,
[Total Profit]
)/[CODE]
I thought this would work as using the Total Profit measure would carry out context transition and Total Profit would be calculated for each row. Actually what happens is I am seeing double counting of duplicate rows, ie sales in the same month of the same product to the same customer.
Experimenting, I find that what is happening is that the context transition is not converting the particular row to a filter for the SUM, it's converting it to a filter of all rows where every column matches the current row. A solution is to actually write out Total Profit with just the underlying columns, rather than a measure with SUMs, but I am now wondering if a bunch of other formulas I have written suffer from this same issue wherever I might have duplicated rows.
Am I understanding what is happening here correctly? Can anyone point me to any blogs or documentation on this point so I can understand this properly.
Thanks
Gary