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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
GoingIncognito
Advocate III
Advocate III

Trouble implementing treatas()

My problem is that I've different tables for a portfolio and a benchmark it is being compared to. These tables are not connected, so I assume I can solve my problem using TREATAS().

 

I've a measure that works as expected:

Weight%, Portfolio =
CALCULATE( DIVIDE( SUM(Position[MARKET_TOTAL_IN_EUR]), CALCULATE( SUM(Position[MARKET_TOTAL_IN_EUR]), ALLSELECTED(Security[CLASS2]), ALLSELECTED(Security[NAME1]) )) )
 
But I need to use it on a matrix that has rows from another table: 'Index'[Class1] and 'Index'[Class2]. So I'm thinking I could solve this with a treatas:
CALCULATE( DIVIDE( SUM(Position[MARKET_TOTAL_IN_EUR]), CALCULATE( SUM(Position[MARKET_TOTAL_IN_EUR]), ALLSELECTED(Security[CLASS2]), ALLSELECTED(Security[NAME1]),  TREATAS(VALUES(Index[CLASS2]),Security[CLASS2] ) )) )
But this doesnt work, and neither does treat as with a summarize:
CALCULATE( DIVIDE( SUM(Position[MARKET_TOTAL_IN_EUR]), CALCULATE( SUM(Position[MARKET_TOTAL_IN_EUR]), ALLSELECTED(Security[CLASS2]), ALLSELECTED(Security[NAME1]), TREATAS(Summarize(Index, Index[CLASS1], Index[CLASS2]), Security[CLASS1], Security[CLASS2] ) )) )
 
What am I doing wrong?
I also can replace the selectedvalues() with IF( isfiltered() ) like this:
if(isfiltered(Security[Name1]), DIVIDE( SUM(Position[MARKET_TOTAL_IN_EUR]), calculate( SUM(Position[MARKET_TOTAL_IN_EUR]), all(Security[Name1])) ),
if(isfiltered(Security[Class2]), DIVIDE( SUM(Position[MARKET_TOTAL_IN_EUR]), calculate( SUM(Position[MARKET_TOTAL_IN_EUR]), all(Security[Class2])) ) ,
if( isfiltered(Security[Class1]), divide( SUM(Position[MARKET_TOTAL_IN_EUR]), calculate( SUM(Position[MARKET_TOTAL_IN_EUR]), all(Security[Class1])) ))))
but again inserting treatas at the end doesn't help. 
1 ACCEPTED SOLUTION
v-gizhi-msft
Community Support
Community Support

Hi,

 

According to your description, i think you have at least three tables and the problem you have due to no relationship berween another two tables.

So i create three tables to test:

81.PNG82.PNG83.PNG

And for your second measure, i make some changes to it:

measure 2 =
CALCULATE (
    DIVIDE (
        SUM ( Position[MARKET_TOTAL_IN_EUR] ),
        CALCULATE (
            SUM ( Position[MARKET_TOTAL_IN_EUR] ),
            ALLSELECTED ( Security[CLASS2] ),
            ALLSELECTED ( Security[NAME1] ),
            TREATAS ( VALUES ( Index[CLASS2] ), Security[CLASS2] ),
            TREATAS ( VALUES ( Security[NAME1] ), Position[name1] )
        )
    )
)

The result shows:

84.PNG

Here is my test pbix file:

pbix 

 

Best Regards,

Giotto Zhi

View solution in original post

2 REPLIES 2
v-gizhi-msft
Community Support
Community Support

Hi,

 

According to your description, i think you have at least three tables and the problem you have due to no relationship berween another two tables.

So i create three tables to test:

81.PNG82.PNG83.PNG

And for your second measure, i make some changes to it:

measure 2 =
CALCULATE (
    DIVIDE (
        SUM ( Position[MARKET_TOTAL_IN_EUR] ),
        CALCULATE (
            SUM ( Position[MARKET_TOTAL_IN_EUR] ),
            ALLSELECTED ( Security[CLASS2] ),
            ALLSELECTED ( Security[NAME1] ),
            TREATAS ( VALUES ( Index[CLASS2] ), Security[CLASS2] ),
            TREATAS ( VALUES ( Security[NAME1] ), Position[name1] )
        )
    )
)

The result shows:

84.PNG

Here is my test pbix file:

pbix 

 

Best Regards,

Giotto Zhi

@v-gizhi-msft 

I am dumbfounded how brilliant and intelligent people come to this forum. Going through your file, I feel like "wow, how smart is this person?". Thank you so much!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors