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
Palmtop
Helper I
Helper I

SumX of 2 Composite Curves

Hello All, 

 

I have 2 different products, Product 1 & Product 2.  For each product, I have plotted the [Sales] and [Expected], in blue and orange respectively.  I have created a new measure that combines the two by taking the [Sales] curve which switches to [Expected] when it begins.  

 

MEASURE = 

var _tbl =
ALLSELECTED ( Expected )
var cutoff =
CALCULATE ( MINX ( _tbl, [Date] ) )

return 

CALCULATE (
    SUM ( Sales[Sales] ),
    FILTER ( _calendar, _calendar[Date] < cutoff )
)
    + SUM ( Expected[Sales] )
    

 

When I select both products however, they do not sum properly.  I believe there is an issue with either my variable 'cutoff' (MINX), or '_tbl' (ALLSELECTED), but I have had no luck fixing it.  Could I please get some advice?

 

Product 1: 

Palmtop_0-1670601138397.png

Product 2: 

Palmtop_1-1670601177944.png

Both Selected:

Palmtop_2-1670601194732.png

See the dip between the start of the 1st and 2nd [Expected] curves. 

 

I have included the sample file below.  Please let me know if you have issues accessing it.  

 

Sample File

 

Note: I would like for the measure to apply to each product first, then sum the result.  Not sum the curves then apply the measure.  

 

Thank you!

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

If you define measures [SumSales] = SUM ( Sales[Sales] ) and [ExpectedSales] = SUM ( Expected[Sales] ), then you can write the composite like this:

 

SUMX (
    'Product',
    IF (
        ISBLANK ( [ExpectedSales] ),
        [SumSales],
        [ExpectedSales]
    )
)

 

Note: IF.EAGER instead of IF may be slightly more efficient here.

View solution in original post

3 REPLIES 3
v-jianboli-msft
Community Support
Community Support

Hi @Palmtop ,

 

Please try:

Measure2 =
VAR _a =
    SELECTCOLUMNS ( 'Product', "Product", [Product] )
VAR _b =
    ADDCOLUMNS (
        _a,
        "cutoff",
            MINX (
                FILTER ( ALL ( 'Expected' ), [Product] = EARLIER ( [Product] ) ),
                [date]
            ),
        "Sales",
            CALCULATE (
                SUM ( Sales[Sales] ),
                FILTER ( 'Sales', [Product] = EARLIER ( [Product] ) )
            ),
        "Expected",
            CALCULATE (
                SUM ( Expected[Sales] ),
                FILTER ( 'Expected', [Product] = EARLIER ( [Product] ) )
            )
    )
VAR _c =
    ADDCOLUMNS (
        _b,
        "Value", IF ( MAX ( '_calendar'[Date] ) < [cutoff], [Sales], [Expected] )
    )
RETURN
    SUMX ( _c, [Value] )

Final output:

vjianbolimsft_0-1670826616329.png

vjianbolimsft_1-1670826631322.png

vjianbolimsft_2-1670826648006.png

Best Regards,

Jianbo Li

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

AlexisOlson
Super User
Super User

If you define measures [SumSales] = SUM ( Sales[Sales] ) and [ExpectedSales] = SUM ( Expected[Sales] ), then you can write the composite like this:

 

SUMX (
    'Product',
    IF (
        ISBLANK ( [ExpectedSales] ),
        [SumSales],
        [ExpectedSales]
    )
)

 

Note: IF.EAGER instead of IF may be slightly more efficient here.

Thank you @AlexisOlson , worked like a charm.  I had tried a sumx before trying the posted measure but had not thought to include the IF ( ISBLANK ( ) ) condition.  

 

@v-jianboli-msft Your solution also worked for me as well, thank you.  

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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