@Roger, CALCULATE can’t directly reference columns from virtual tables. You need to materialize the virtual table and then iterate over it to perform the calculation.
Try this revision:
TONNAGE TOTAL INDUSTRIE FORM VIRTUAL =
VAR CurrentYear =
SUMMARIZE(
MAANDRAPPORTEN,
MAANDRAPPORTEN[VOEDSELBANK],
MAANDRAPPORTEN[Periode],
MAANDRAPPORTEN[PROD ID],
MAANDRAPPORTEN[HEADING],
"HOEVELEID IN KG", SUM(MAANDRAPPORTEN[KG NA RAMASSE])
)
VAR MergedTables =
SUMMARIZE(
FILTER(
ADDCOLUMNS(
UNION(CurrentYear, 'HISTORIEK'),
"IN or OUT", LOOKUPVALUE(SOURCES[VOORRAAD], SOURCES[HEADING], [HEADING]),
"KG VB", [HOEVELEID IN KG]
),
[IN or OUT] = "IN"
),
[Periode],
[VOEDSELBANK],
[heading],
[IN or OUT],
[KG VB]
)
RETURN
CALCULATE(
SUMX(
FILTER(
MergedTables,
MergedTables[HEADING] = "DISTRIBUTION DISTRIBUTIE"
),
[KG VB]
)
)
Hello,
I found the solution myself after some debugging the code
for whom is interested below the solution for the measure
calculating the sum from a column in a virtual table.
solution is to wrap the sumx() in a calculate to make it work.
the KG column is also in the combinedData Table
a tip for the one struggling with the variables
I found the video by Brian Julius very well explained
below the link Top 5 Tips & Tricks For Debugging Virtual Tables In Power BI (youtube.com)