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
Jeanxyz
Post Prodigy
Post Prodigy

how to remove filters in a virtual table

I have written a DAX measure to calculate revenue of past 12 months (TTM), it's not working because the Scenario table is filtered by some slicers, how can I remove the filter on scenario table? Please help update the highlighted part below.

 

 

Actual_TTM(M) =
var max_year= convert(max(Scenario[Scenario Year]),integer)
var max_month=SELECTEDValue(Period[Period Num])
var max_date=eomonth(date(max_year,max_month,1),0)
var min_date=date(year(eomonth(max_date,-11)),month(eomonth(max_date,-11)),1)


VAR AggregatedSalesInCurrency =
    ADDCOLUMNS(
        SUMMARIZE(
            FILTER(all(FactTable), FactTable[TGK_CALENDAR_KEY]<=max_date && FactTable[TGK_CALENDAR_KEY]>=min_date && FactTable[Scenario Type Code]="CONSO"),
            Scenario[Scenario Code],
          //how can I remove the filter on scenario table?
            'Transaction Currency'[Transaction Currency Code]
        ),
        "@SalesAmount",
        [Balance Sheet Amount Monthly Converted Monthly Rate],
        "@Rate",
        CALCULATE(
            SELECTEDVALUE('Exchange Rate'[Average Exchange Rate]),
            'Period'[Period Num] = MAX('Period'[Period Num])
        )
    )
return
SUMX(
        AggregatedSalesInCurrency,
        IF(
            NOT(ISBLANK([@Rate])),
            [@SalesAmount] * [@Rate],
            BLANK()
        )
    )
1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @Jeanxyz 

 

Please try this:

Actual_TTM(M) =
VAR max_year =
    CONVERT ( MAX ( Scenario[Scenario Year] ), INTEGER )
VAR max_month =
    SELECTEDVALUE ( Period[Period Num] )
VAR max_date =
    EOMONTH ( DATE ( max_year, max_month, 1 ), 0 )
VAR min_date =
    DATE ( YEAR ( EOMONTH ( max_date, -11 ) ), MONTH ( EOMONTH ( max_date, -11 ) ), 1 )
VAR AggregatedSalesInCurrency =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER (
                    ALL ( FactTable ),
                    FactTable[TGK_CALENDAR_KEY] <= max_date
                        && FactTable[TGK_CALENDAR_KEY] >= min_date
                        && FactTable[Scenario Type Code] = "CONSO"
                ),
                Scenario[Scenario Code],
                //how can I remove the filter on scenario table?
                'Transaction Currency'[Transaction Currency Code]
            ),
            "@SalesAmount", [Balance Sheet Amount Monthly Converted Monthly Rate],
            "@Rate",
                CALCULATE (
                    SELECTEDVALUE ( 'Exchange Rate'[Average Exchange Rate] ),
                    'Period'[Period Num] = MAX ( 'Period'[Period Num] )
                )
        ),
        ALL ( 'Scenario' )
    )
RETURN
    SUMX (
        AggregatedSalesInCurrency,
        IF ( NOT ( ISBLANK ( [@Rate] ) ), [@SalesAmount] * [@Rate], BLANK () )
    )

The calculatetable() function can use filters on the table.

 

If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

1 REPLY 1
v-zhengdxu-msft
Community Support
Community Support

Hi @Jeanxyz 

 

Please try this:

Actual_TTM(M) =
VAR max_year =
    CONVERT ( MAX ( Scenario[Scenario Year] ), INTEGER )
VAR max_month =
    SELECTEDVALUE ( Period[Period Num] )
VAR max_date =
    EOMONTH ( DATE ( max_year, max_month, 1 ), 0 )
VAR min_date =
    DATE ( YEAR ( EOMONTH ( max_date, -11 ) ), MONTH ( EOMONTH ( max_date, -11 ) ), 1 )
VAR AggregatedSalesInCurrency =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER (
                    ALL ( FactTable ),
                    FactTable[TGK_CALENDAR_KEY] <= max_date
                        && FactTable[TGK_CALENDAR_KEY] >= min_date
                        && FactTable[Scenario Type Code] = "CONSO"
                ),
                Scenario[Scenario Code],
                //how can I remove the filter on scenario table?
                'Transaction Currency'[Transaction Currency Code]
            ),
            "@SalesAmount", [Balance Sheet Amount Monthly Converted Monthly Rate],
            "@Rate",
                CALCULATE (
                    SELECTEDVALUE ( 'Exchange Rate'[Average Exchange Rate] ),
                    'Period'[Period Num] = MAX ( 'Period'[Period Num] )
                )
        ),
        ALL ( 'Scenario' )
    )
RETURN
    SUMX (
        AggregatedSalesInCurrency,
        IF ( NOT ( ISBLANK ( [@Rate] ) ), [@SalesAmount] * [@Rate], BLANK () )
    )

The calculatetable() function can use filters on the table.

 

If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

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.