cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
avachris
Frequent Visitor

Different behavior of treatas

issue: when I use treatas on a variable table within a measure I am seeing different behavior if I treatas the column to a fact or dimension table. 

when I apply treatas to change the data lineage to the dimension table, the relationship does not hold and the filter from the dimension table is not considered. 

However when the treatas is pointed at the fact table (which has a many to 1 relationship to the same dimension table) the behavior appears to work correctly. 

is there something going on within treatas which requires a condition to work?  Is it possible that if I am changing the data type within dax on the key this is messing it up?

3 REPLIES 3
johnt75
Super User
Super User

I don't think its TREATAS messing things up, I just ran

DEFINE
VAR ProdKeys = { 599, 1885, 1895 }

EVALUATE
ROW(
    "Using Product", 
    CALCULATE ( [Sales Amount], TREATAS ( ProdKeys, 'Product'[ProductKey] )),
    "Using Sales", 
    CALCULATE ( [Sales Amount], TREATAS ( ProdKeys, 'Sales'[ProductKey] ))
)

on dax.do and it gave the same answer for both calculations, as expected.

What did you mean by changing the data type on the key ?

avachris
Frequent Visitor

sure - here is an example of the measure i'm using

 

MeasureWhichWorks =
var tables =
ADDCOLUMNS(
TREATAS (
    SELECTCOLUMNS (
        DisconnectedTable,
        [DimensionKey]
    ),
    'FactTable'[DimensionKey]
)
,"@Sum",calculate([MeasureIwantToSum)))

return sumx(tables,[@Sum])
 
MeasureWhichDoesn'tWork=
var tables =
ADDCOLUMNS(
TREATAS (
    SELECTCOLUMNS (
        DisconnectedTable,
        [DimensionKey]
    ),
    'DimensionTbl'[DimensionKey]
)
,"@Sum",calculate([MeasureIwantToSum)))

return sumx(tables,[@Sum])
 
The issue I have here is that I want to use treatas to the dimension tables so that the filter propogates and then the subsequent measures i'm refering will work properly. 
johnt75
Super User
Super User

Do you have an example you can share ?

From what you've said it sounds like you are trying to define a table in a variable and then recalculate it using TREATAS. That won't work, a variable is only calculated once, when it is define. Trying to recalculate later won't change the result. Variables aren't really variable, they're more like constants.

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors
Top Kudoed Authors