Hi @vernonwyng,
Something oddās going on hereā¦
I can create the required logic in M
And obviously in a DAX table as well
BUT when I create the same DAX logic in a virtual table to create a Measure, I canāt seem to get it to workā¦ even after trying to break lineage I come up empty maybe someone with fresh eyes can take another stab at thatā¦
Anyway turning it into the smallest possible physical table, hooking it up to your model and hiding it from view - works. Although the relationship is not required, you can create that virtually.
Total Revenue (DAX table) =
SUMX( TempTable, [@SlipAmount] ) + [Item Revenue]
Although youāll find 2 solutions in the file attached below, this is the Measure thatās bugging me and I canāt seem to get to work properly.
Total Revenue v2 (doesn't work) =
VAR vAllItems = ALLNOBLANKROW( 'Specific ITMCODE'[ITMCODE] )
VAR vAllItems2 =
ADDCOLUMNS(
ALLNOBLANKROW( 'Specific ITMCODE'[ITMCODE] ),
"@NewItemCode", [ITMCODE] &""
)
VAR vAllSlips =
ADDCOLUMNS(
VALUES( 'Sample Table'[SLIP] ),
"@Num of Items", CALCULATE( COUNTROWS( 'Sample Table' ), FILTER( VALUES('Sample Table'[ITMCODE]), 'Sample Table'[ITMCODE] IN vAllItems ))
)
VAR vSlipItems =
ADDCOLUMNS(
ADDCOLUMNS(
FILTER( SELECTCOLUMNS( 'Sample Table', "@Item", [ITMCODE], "@Slip", [SLIP] ),
[@Item] IN vAllItems
), "@Num of Items", MAXX( FILTER(vAllSlips, [SLIP] = [@Slip] ), [@Num of Items] )
), "AvgSlipRevenue", SUMX( FILTER('Sample Table', 'Sample Table'[SLIP] = [@Slip] && NOT('Sample Table'[ITMCODE]) IN vAllItems ), [AMOUNT] ) / [@Num of Items],
"@NewItemCode", MAXX( FILTER(vAllItems, [ITMCODE] = [@Item] ), [@Item] ) &""
)
VAR vTable =
SELECTCOLUMNS( vSlipItems,
"@Item", [@NewItemCode],
"@AvgSlipAmt", [AvgSlipRevenue]
)
VAR nTable =
ADDCOLUMNS( SELECTCOLUMNS( vAllItems2, "Item", [@NewItemCode] ),
"@Amount", SUMX( FILTER( vTable, [@Item] = EARLIER([Item])), [@AvgSlipAmt] )
)
RETURN
CALCULATE(
SUMX( nTable, [@Amount] ),
//FILTER( SELECTCOLUMNS( nTable, "@Item", [Item]), [@Item] IN VALUES( 'Specific ITMCODE'[ITMCODE] ))
TREATAS( SELECTCOLUMNS( nTable, "@Item", [Item]), 'Specific ITMCODE'[ITMCODE] )
) + [Item Revenue]
Hereās your sample file. sample table.pbix (41.9 KB)
I hope this is helpful.