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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
razmochaev
Helper I
Helper I

Formula execution results in Excel crash while DAX Studio works fine

Hi everyone.

I ran into the problem and I think it's because of imperfect formula.

I need to compute costs attributable to projects only for projects that had sales in a given period. Also, the costs should be accumulated between period of current sale and previos sale.

 

The data model is in Russian, so I give the translation:

Проекты = Projects

Календарь[Дата] = Calendar[Date]

Продажи = Sales

[Выручка] = [SalesAmount]

Себестоимость = Cost Of Services Rendered

 

The DAX code I've come up with:

EVALUATE
VAR ProjectsSalesDates =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZECOLUMNS ( 'Проекты'[id], 'Календарь'[Дата] ),
            "Продажи", [Выручка]
        ),
        NOT ( ISBLANK ( 'Проекты'[id] ) )
            && [Продажи] > 0
    )
VAR ProjSalesPrevDates =
    ADDCOLUMNS (
        ProjectsSalesDates,
        "PrevSalesDate", MAXX (
            (
                VAR CurrProject = [id]
                VAR CurrDate = [Дата]
                VAR ProjectDates =
                    FILTER ( ProjectsSalesDates, [id] = CurrProject && [Дата] < CurrDate )
                RETURN
                    ProjectDates
            ),
            [Дата]
        )
    )
VAR ProjectsCosts =
    ADDCOLUMNS (
        ProjSalesPrevDates,
        "Себестоимость трудозатрат", CALCULATE (
            [2.2. Стоимость трудозатрат],
            (
                VAR CurrDate = [Дата]
                VAR PrevDate = [PrevSalesDate]
                VAR CostPeriod =
                    DATESBETWEEN ( 'Календарь'[Дата], PrevDate, CurrDate )
                RETURN
                    CostPeriod
            )
        ),
        "Себестоимость прямых затрат", CALCULATE (
            [Прямые затраты],
            (
                VAR CurrDate = [Дата]
                VAR PrevDate = [PrevSalesDate]
                VAR CostPeriod =
                    DATESBETWEEN ( 'Календарь'[Дата], PrevDate, CurrDate )
                RETURN
                    CostPeriod
            )
        )
    )
VAR Result =
    ADDCOLUMNS (
        ProjectsCosts,
        "Себестоимость", [Себестоимость трудозатрат] + [Себестоимость прямых затрат]
    )
RETURN
    SUMX ( Result, [Себестоимость]) 

 In DAX Studio is works fine and returns the following table:

Screenshot_1.pngIt returns 529 rows and execution time is 3250 ms.

But when I input this formula in Excel, it crashes :-(.

 

If anyone could give me a hint, whether it's due to bad formula of something else, I'd be very grateful!

3 REPLIES 3
razmochaev
Helper I
Helper I

I also tested it in PowerBI and it works pretty well, but in different versions of Excel it results in a crash.

Anonymous
Not applicable

First off, you should never use SUMMARIZECOLUMNS in a measure since this function does not respect context transition. Then, the measure (is it a measure or just a query?) seems to me to be a bit too complex with calculations that are materialized, probably unnecessary, thus making the calculations slower than they could be.

Secondly, what's the exact error message you get?

Best
D

Thank you for the remarks! I've made some improvements in the formula and now it doesn't crash. Still, I didn't get the result I wanted, so I guess this topic must be closed.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.