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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
6mon
Helper II
Helper II

SELECTCOLUMNS / SUMMARIZE broken in calculated table Whereas it works in EVALUATE in SSMS

2019-07-02 16_04_31-Integration Services Project1 - Microsoft Visual Studio.png2019-07-02 16_04_46-Integration Services Project1 - Microsoft Visual Studio.png

2019-07-03 10_47_50-MDXQuery4.mdx - pc-test_srv_test.COST_ACTIVITY_69069 (TPL_sbenoit)_ - Microsoft .png

 

I'm stumped, guys!

Both parts of this simple subtraction give the right result.

SQL Server version is 13.0.5337

 

For what it's worth I get the exact same result whether I use SUMMARIZECOLUMNS or ADDCOLUMNS and with or without a CALCULATE wrapping the measure.

4 REPLIES 4
Stachu
Community Champion
Community Champion

Qhat's the syntax for [PROFIT_CUM]? that's the measure that's gets evaluated incorrectly, correct?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

It's a pretty simple one : it's the difference between two measures (see the screenshot between the two up there ^^ )

 

Both measures (INCOME_PLANNED_CUM and COST_CUM) evaluate correctly in the two 'environments'.

Stachu
Community Champion
Community Champion

hmm, for some reason I thought that the [PROFIT_CUM_CALC] is based on [PROFIT_CUM] as they were both inconsistent between the pictures.

 

It's a nested calculation, so without details on what's happening in the nested measures there is no much to investigate



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

The broken one is PROFIT_CUM.

PROFIT_CUM_CALC is where I recreate the measure using the aggregated 'base measures' instead of aggregating the PROFIT_CUM measure. Here's the code for the evaluate : 

evaluate 
selectcolumns(
    SUMMARIZE(FACT_COST_ACTIVITY,FACT_COST_ACTIVITY[PROJECT NAME]),
    "PROJECT NAME",[PROJECT NAME],
    "PROFIT_CUM",[PROFIT_CUM],
    "COST_CUM",[COST_CUM],
    "INCOME_PLANNED_CUM",[INCOME_PLANNED_CUM],
    "PROFIT_CUM_CALC",[INCOME_PLANNED_CUM]-[COST_CUM]
)

 

Here's the full breakdown of the broken measure : 

PROFIT_CUM := [INCOME_PLANNED_CUM]-[COST_CUM]

 

INCOME_PLANNED_CUM:= 
SUMX(
    VALUES(FACT_COST_ACTIVITY[ID_DIM_ACTIVITY]);
    VAR 
        LAST_DATES = 
        CALCULATE(
            MAX(FACT_COST_ACTIVITY[THE_DATE])
        )

RETURN
    CALCULATE(
        sum(FACT_COST_ACTIVITY[INCOME_PLANNED_CUM_COL]);
        DIM_DATE[THE_DATE] = LAST_DATES
    )
)
INCOME_PLANNED_CUM_COL :=
IF(
    FACT_COST_ACTIVITY[EXPENSE_ONLY_COL]; //BOOLEAN column in related dimension
    FACT_COST_ACTIVITY[COST_REAL_CUM]; //column
    FACT_COST_ACTIVITY[INCOME_BUDGET]  //column
    * 
    MIN(
        FACT_COST_ACTIVITY[QUANTITY_RATIO_CUM_COL];
        1
    )
)
QUANTITY_RATIO_CUM_COL :=
IF(
    FACT_COST_ACTIVITY[EXPENSE_ONLY_COL] = 1 && FACT_COST_ACTIVITY[QUANTITY_REAL_CUM] > 0;
    1;
    DIVIDE(
        FACT_COST_ACTIVITY[QUANTITY_REAL_CUM]; //column
        FACT_COST_ACTIVITY[QUANTITY_BUDGET_COL]; //column (in related table)
        0
    )
)
COST_CUM:=
SUMX(
    VALUES(FACT_COST_ACTIVITY[ID_DIM_ACTIVITY]);
    VAR 
        LAST_DATES = 
        CALCULATE(
            MAX(FACT_COST_ACTIVITY[THE_DATE])
        )

RETURN
    CALCULATE(
        sum(FACT_COST_ACTIVITY[COST_REAL_CUM]); //column
        DIM_DATE[THE_DATE] = LAST_DATES
    )
)
+ 
IF(not ISBLANK([QUANTITY_CUM]);0)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.