Forum Discussion

Amit92's avatar
Amit92
Regular Visitor
1 year ago
Solved

Using Treatas without Filtering the Dataset

Hi Everyone,  Hope you are doing good. I have 2 sample datasets as below:   I have created a measure named  Amt_Total_Treatas  =  CALCULATE(SUM(Amt[Amt]), TREATAS(VALUES('Group'[Cu...
  • johnt75's avatar
    1 year ago

    I think the below should work. It will give the value for the current group if the group is in scope, otherwise it will give the total

    Amt Total Treatas =
    VAR AllAmtNames =
        DISTINCT ( Amt[Cust] )
    VAR AllGroupNames =
        DISTINCT ( ALL ( Group[Cust] ) )
    VAR MissingAmtNames =
        EXCEPT ( AllAmtNames, AllGroupNames )
    VAR Result =
        IF (
            ISINSCOPE ( Group[Cust] ),
            CALCULATE ( SUM ( Amt[Amount] ), TREATAS ( VALUES ( Group[Cust] ), Amt[Cust] ) ),
            CALCULATE (
                SUM ( Amt[Amount] ),
                TREATAS ( UNION ( VALUES ( Group[Cust] ), MissingAmtNames ), Amt[Cust] )
            )
        )
    RETURN
        Result