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

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

Reply
jpbi23
Helper I
Helper I

calculate using sum and filter

I have this measure which sums up amount based on the filters applied in the formula. Then I subtract 'On hold service revenue' from 'Amount'

 

I have many formulas in the dataset like this. Visual (table) is taking too long to load after I implemented this logic. 

 

I'm wondering if there is a better way to write this formula which would perform better.

 

 

Remaining Months Recurring Services Revenue =
 
VAR SelectedDate = SELECTEDVALUE('Date'[PERIOD])
VAR EndDate = EDATE(SelectedDate, 60)
 
RETURN

CALCULATE(
    SUM(MASTER_REVENUE[AMOUNT]),
    FILTER(
        MASTER_REVENUE, MASTER_REVENUE[REVENUE_CATEGORY] in {"Recurring Services"} &&
        MASTER_REVENUE[PERIOD] > EndDate

        - MASTER_REVENUE[On hold Recurring Service]
    )
)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jpbi23 ,

I am glad to help you.
According to your description, I suggest you can create a virtual table in measure as an intermediate amount to increase the execution efficiency of dax, the modified code is as follows:

 

Remaining Months Recurring Services Revenue =
VAR SelectedDate =
    SELECTEDVALUE ( 'Date'[PERIOD] )
VAR EndDate =
    EDATE ( SelectedDate, 60 )
VAR table_ =
    FILTER (
        MASTER_REVENUE,
        MASTER_REVENUE[PERIOD] > EndDate - MASTER_REVENUE[On hold Recurring Service]
    )
RETURN
    CALCULATE (
        SUM ( MASTER_REVENUE[AMOUNT] ),
        FILTER ( table_, table_[REVENUE_CATEGORY] IN { "Recurring Services" } )
    )

 

For the optimization of the above code, I made test data and tested the performance of your previous dax code and the optimized dax code using virtual tables

Here is my test data (with 500 rows):

vjtianmsft_0-1713948343285.png

Write using virtual tables:

 

M_1 = 
VAR table_ =
    FILTER (
        Test_,
        Test_[saleTime] <=NOW()
    )
RETURN
    CALCULATE (
        SUM ( Test_[amount] ),
        FILTER ( table_, Test_[fruitName] IN { "apple" } )
    )

 

Virtual table writes are not used:

 

M_2 = 
    CALCULATE (
        SUM ( Test_[amount] ),
        FILTER ( Test_, Test_[fruitName] IN { "apple" } &&  Test_[saleTime] <=NOW() )
    )

 

I used each of these two MEASURES six times

The top six times are M_1

The bottom six times is M_2

The test results are as follows:

vjtianmsft_1-1713948434142.png

 

The average execution time for M_1 = 123ms
The average execution time for M_2 = 156ms

vjtianmsft_2-1713948459503.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,
Carson Jian,
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

2 REPLIES 2
jpbi23
Helper I
Helper I

tahnk you for the reply! is there a better way to do the subtraction? Currently its in the filter. It needs to be,

Amount - On hold recurring service

Anonymous
Not applicable

Hi @jpbi23 ,

I am glad to help you.
According to your description, I suggest you can create a virtual table in measure as an intermediate amount to increase the execution efficiency of dax, the modified code is as follows:

 

Remaining Months Recurring Services Revenue =
VAR SelectedDate =
    SELECTEDVALUE ( 'Date'[PERIOD] )
VAR EndDate =
    EDATE ( SelectedDate, 60 )
VAR table_ =
    FILTER (
        MASTER_REVENUE,
        MASTER_REVENUE[PERIOD] > EndDate - MASTER_REVENUE[On hold Recurring Service]
    )
RETURN
    CALCULATE (
        SUM ( MASTER_REVENUE[AMOUNT] ),
        FILTER ( table_, table_[REVENUE_CATEGORY] IN { "Recurring Services" } )
    )

 

For the optimization of the above code, I made test data and tested the performance of your previous dax code and the optimized dax code using virtual tables

Here is my test data (with 500 rows):

vjtianmsft_0-1713948343285.png

Write using virtual tables:

 

M_1 = 
VAR table_ =
    FILTER (
        Test_,
        Test_[saleTime] <=NOW()
    )
RETURN
    CALCULATE (
        SUM ( Test_[amount] ),
        FILTER ( table_, Test_[fruitName] IN { "apple" } )
    )

 

Virtual table writes are not used:

 

M_2 = 
    CALCULATE (
        SUM ( Test_[amount] ),
        FILTER ( Test_, Test_[fruitName] IN { "apple" } &&  Test_[saleTime] <=NOW() )
    )

 

I used each of these two MEASURES six times

The top six times are M_1

The bottom six times is M_2

The test results are as follows:

vjtianmsft_1-1713948434142.png

 

The average execution time for M_1 = 123ms
The average execution time for M_2 = 156ms

vjtianmsft_2-1713948459503.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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 Kudoed Authors