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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Problems with SUMIF equivalent

Hello, 


I am trying to write an equivalent for SUMIF in PowerBI. I am using "less or equal" expression in two cases: with integer and with measure (which contains the same integer). And as a result, I suddenly get different answers (see measures Cumul & Cumul1 in attached file). 

 

Could you please help me solve this issue? What can be done to include measure to "less or equal" expression?

Many thanks in advance. 

The file can be found here: https://drive.google.com/file/d/1mW4SHrr6Yp-dDvXy-Gu45xVlGtLxiWeC/view?usp=sharing

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create measure like DAX below.

 

Cumul =CALCULATE(SUM(Sheet1[Value]),FILTER(ALLSELECTED(sheet1 ),Sheet1[Product]=MAX(Sheet1[Product]) &&Sheet1[Date] <=MAX(Sheet1[Date] ) ))

 

For the variable in measure or column  , you may refer to the link: https://radacad.com/caution-when-using-variables-in-dax-and-power-bi.

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

4 REPLIES 4
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create measure like DAX below.

 

Cumul =CALCULATE(SUM(Sheet1[Value]),FILTER(ALLSELECTED(sheet1 ),Sheet1[Product]=MAX(Sheet1[Product]) &&Sheet1[Date] <=MAX(Sheet1[Date] ) ))

 

For the variable in measure or column  , you may refer to the link: https://radacad.com/caution-when-using-variables-in-dax-and-power-bi.

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

amitchandak
Super User
Super User

@Anonymous , I check fine. Not able to make much sense. Can you let me know Output in table format.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Dear @amitchandak

I’m sorry, I didn’t understand you clearly. Could you please give me more details of the information you need from me?


If to give a brief summary of the task, here it is. 

I have a table with sales of 2 products by weeks. I have a slicer for product and a slicer for week. 
Each week has its number (Code). 

I want to find a sum of sales of specific product (chosen by slicer) for all weeks from the first till the week which is selected in another slicer. 

I understand that if, for instance, Week 3 is selected, I should sum by all weeks which have numbers 1, 2 and 3 (so here 3 is the number of the last week that should be included). 

 

I think that my SUMIF formula should be like this:


Cumul = CALCULATE(SUM(Sheet1[Value]),FILTER(sheet1,Sheet1[Code_vlookup]<=[NoPeriod]),FILTER(sheet1,Sheet1[Product]=selectedvalue(Sheet2[Product])))
 
But this formula shows incorrect result. 

For the formula above, [NoPeriod] is the measure that shows number of week by its full name (3 for Week 3, 2 for Week 2 etc.). In my example, [NoPeriod] value is 3. 
 
But if I change [NoPeriod] for just integer 3 instead:
Cumul1 = CALCULATE(SUM(Sheet1[Value]),FILTER(sheet1,Sheet1[Code_vlookup]<=3),FILTER(sheet1,Sheet1[Product]=selectedvalue(Sheet2[Product])))
 
I'll get a different result (correct one). 

I am puzzling about the reason of such thing. 

The tables used are the following:
Sheet 1
ProductDateValue
TeaW11
TeaW212
TeaW3223
TeaW43304
TeaW544005
CoffeeW12
CoffeeW223
CoffeeW3334
CoffeeW44405
CoffeeW555006

 

Sheet2:

Product
Tea
Coffee

 

Sheet 3: 

DateCode
W11
W22
W33
W44
W55
Greg_Deckler
Community Champion
Community Champion

@Anonymous - Probably is because of the context in which the measure is executing is throwing off the number. Often you can get around this by using a variable (VAR) at the start of a formula and setting it equal to your measure. This way you can often avoid context issues with having the measure buried in the formula somewhere.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors