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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.