Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors