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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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
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! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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