Forum Discussion
Variable table not containing rows from another table
The user will select from the right filter panel a Product.
That needs to come from the product dimension table.
That is true. Small update on my progress:
1) First I tried to extract from the FACT, all the subcategories that have a discounted product
VAR listofsubcat = SELECTCOLUMNS( FILTER( FACT, FACT[FLAG_Product_Discount] = 1), -- just a flag I did in the backend to identify easily the discounted products "DiscountedSubcat", RELATED(DIM[Subcategory Code]) )
2) Then I tried to calculate the SUM of prices for the remaining products, but whatever I am trying, I get a correct total sum, but in incorrect row level sum, by period:
I tried many variations to get the result similar to the below logic:
VAR listofsubcat2 = SELECTCOLUMNS(FILTER(DIM, DIM[Subcategory Code] IN listofsubcat), "_subcat", DIM[Subcategory Code])
RETURN SUMX( ADDCOLUMNS(FILTER(FACT, NOT (RELATED(DIM[Subcategory Code) IN listofsubcat2) ), "_price", FACT[Price] ), [_price] )
Here listofsubcat2 correctly extracts the subcategories which have a discounted product, if I hardcode the name in the measure in the NOT IN part, like that :
RETURN SUMX( ADDCOLUMNS(FILTER(FACT, NOT (RELATED(DIM[Subcategory Code) IN {"Subcat1", "Subcat2" etc) ), "_price", FACT[Price] ), [_price] )
--> it works, but of course I need the formula to be dynamic based on user's selection.
Tried also with calculatetable:
RETURN SUMX(CALCULATETABLE(FACT, NOT ( DIM[Subcategory Code] IN listofsubcat2 ) ), FACT[Price])
Same wrong result. Apparently Power BI is somehow overwriting my filter context while doing the individual row sum ? Also I checked further and even if some periods show the correct sum, if you do a countrows in Power BI vs the returned rows in SQL, the number is different so probably "behind the curtains" they are wrong as well.
Any idea what am I doing wrong and how can I make Power BI respect my filter without having to manually hardcore the values that I want to exclude ?
Thank you !
- lbendlin2 years agoSuper User
Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.- AndreiiBC2 years agoFrequent Visitor
Hi lbendlin ,
You can find the pbix file here : https://we.tl/t-QviFhwzCih
You also have an example there with the result I get now vs. the expected result.
Thank you!