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
setis
Post Partisan
Post Partisan

SUMX and IF

Dear experts,

 

I have a measure that captures the last date on a date slicer:

MaxSelectedDate = 
CALCULATE(
    MAX(Calendar_NAV[Date]);
    ALLSELECTED(Calendar_NAV[Date]))

 

Then I have a measure that calculates a value in Table 1. 

 

I need a measure that itinerates Table 1 and calculates the measure only if a the column "Date Closed" is after the above measure [MaxSelectedDate].

 

This is what I'm trying without success:

VAR Measure = My measure goes here
RETURN
SUMX('Table1';
CALCULATE(
    IF(
        'Table1'[Date closed]>[MaxSelectedDate];
        Measure;"")
        ))

 

Could somebody help please?

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @setis 

 

Based on your description, you may try to modify the measure as follows.

Measure = 
SUMX(
     ALLSELECTED('Table1');
     CALCULATE(
        IF(
        'Table1'[Date closed]>[MaxSelectedDate];
        My measure goes here;""
        )
     )
)

 

Best Regards

Allan

 

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

View solution in original post

5 REPLIES 5
v-alq-msft
Community Support
Community Support

Hi, @setis 

 

Based on your description, you may try to modify the measure as follows.

Measure = 
SUMX(
     ALLSELECTED('Table1');
     CALCULATE(
        IF(
        'Table1'[Date closed]>[MaxSelectedDate];
        My measure goes here;""
        )
     )
)

 

Best Regards

Allan

 

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

Nishantjain
Continued Contributor
Continued Contributor

@setis 

 

When you use variable, they are not evaluated in the context filter you apply in the calculate function. Instead of putting your "Measure" as variable, you need to put it directly in the calcuate function

 

// Don't put your measure as variable if you are trying to change the context filter)
//VAR Measure = My measure goes here
RETURN
SUMX('Table1';
CALCULATE(
    IF(
        'Table1'[Date closed]>[MaxSelectedDate];
        My measure goes here;"")
        ))

I am not sure why you need to put it as a variable, but using variable within calcuate will not change the value return by the measure i.e. the context filter will not change. 

@Tad17 thanks for your help.

 

@Nishantjain It seems like in the first argument of the IF, where you put 

'Table1'[Date closed]

 it only let me put a measure. 

Please see the report here reproducing the issue https://drive.google.com/file/d/1bQyBNs-7uu8e4sOiVRZnEkz57fKQXFMl/view?usp=sharing 

I need the slicer as it is, but I need to show in the measure only the values where the closed date is > to the max date of the slicer.

 

Thanks in advance

Hi,

This should get you started.  The figure in the Grand total is wrong but i hope someone sle can help you with it.  Download the PBI file from here.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Tad17
Solution Sage
Solution Sage

Hey @setis 

 

Try:

Calculate(SUM(Table[column],FILTER(Table1, Table1[Date Closed]>MaxSelectedDate))

or

=SUMX(FILTER(Table1, Table1[Date Closed]>MaxSelectedDate),[Column])

 

I'm not sure I got it quite right, but it should be close.

 

If this helps please kudo.

If this solves your problem please accept it as a solution.

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!

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.