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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
athgeor
Frequent Visitor

Sum values of Measure 1 when condition applies to measure 2

Hi all, 

 

I'm trying to create a measure that sums the values of a measure (1) when the values of another measure (2) is above 20. 

 

I have tried different measures I found in the forum but none of them seems to work. (Note: Measure 1 and Measure 2 can change depending on the time bucket I apply)

 

e.g I tried  CALCULATE( [Customers], IF ([Spend]>20)), I tried variations of SUMX and didn't get a result

 

 Measure 1Measure 2Measure Neeeded
Time BucketCustomersSpend 
00:00 - 00:15104510
00:15 - 00:30254025
00:30 - 00:45304030
00:45 - 01:00510 
01:00 - 01:158020 
01:15 - 01:309010 
01:30 - 01:4510015 
01:45 - 02:0012058120
02:00 - 02:15905090

 

Can anyone help?

 

Many thanks in advance

1 ACCEPTED SOLUTION

I created a _Summary_ table that has columns named [@Customers] and [@Spend] and the used SUMX to iterate over the _Summary_ table, filtering on the [@Spend] column and summing on the [@Customers] column.

 

This pattern works assuming [Customers] and [Spend] are columns of 'Table'. If those are actually measures instead of columns, then the DAX is slightly simpler:

BigSpenders =
VAR _Summary_ =
    ADDCOLUMNS (
        SUMMARIZE ( 'Table', 'Table'[Time Bucket] ),
        "@Customers", [Customers],
        "@Spend", [Spend]
    )
RETURN
    SUMX ( FILTER ( _Summary_, [@Spend] > 20 ), [@Customers] )

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

You can create a calculated table within a measure that you then apply SUMX to like this:

 

BigSpenders =
VAR _Summary_ =
    ADDCOLUMNS (
        SUMMARIZE ( 'Table', 'Table'[Time Bucket] ),
        "@Customers", CALCULATE ( SUM ( 'Table'[Customers] ) ),
        "@Spend", CALCULATE ( SUM ( 'Table'[Spend] ) )
    )
RETURN
    SUMX ( FILTER ( _Summary_, [@Spend] > 20 ), [@Customers] )

Hi @AlexisOlson 

 

I appreciate the help.

 

I don't seem to be able to select the measures in the sum functions...

 

I believe this works with the native columns but does not seem to work with my measures (@Customers & @Spend)

 

 

I created a _Summary_ table that has columns named [@Customers] and [@Spend] and the used SUMX to iterate over the _Summary_ table, filtering on the [@Spend] column and summing on the [@Customers] column.

 

This pattern works assuming [Customers] and [Spend] are columns of 'Table'. If those are actually measures instead of columns, then the DAX is slightly simpler:

BigSpenders =
VAR _Summary_ =
    ADDCOLUMNS (
        SUMMARIZE ( 'Table', 'Table'[Time Bucket] ),
        "@Customers", [Customers],
        "@Spend", [Spend]
    )
RETURN
    SUMX ( FILTER ( _Summary_, [@Spend] > 20 ), [@Customers] )

Thanks @AlexisOlson, the last code worked like a charm! Many thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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