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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
PowerBITestingG
Resolver I
Resolver I

Iterate through a measure

I have been looking around the forum to find the answer but no luck yet

 

I have this table

CountryCondition

Quantity (measure)

Wanted measure
France1515
Italy0215
Spain11015

 

I want to basically get the total of my Quantity measure based on the condition

 

I would have thought = sumx(filter(table,condition<>1), Quantity ( measure)) would have done the trick, but it brings the exact same result. I am filtering the table.

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@PowerBITestingG I would think:

Wanted measure =
  VAR __Table = SUMMARIZE(ALLSELECTED('Table'),[Country],[Condition],"Quantity",[Quantity])
RETURN
  SUMX(FILTER(__Table,[Condition] = 1),[Quantity])


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...

View solution in original post

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

@PowerBITestingG I would think:

Wanted measure =
  VAR __Table = SUMMARIZE(ALLSELECTED('Table'),[Country],[Condition],"Quantity",[Quantity])
RETURN
  SUMX(FILTER(__Table,[Condition] = 1),[Quantity])


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...

@Greg_Deckler  Can you see any future issues from using allselected inside a sumx? or we are not using it directly in it, so its not a problem?

 

Thank you!

@PowerBITestingG ALLSELECTED just removes the direct filters within the visual, so in this case Country and Condition, for example. It preserves all of the other filters coming from visual selections in other visuals. You can use ALLSELECTED on it's own, wrapped in a FILTER or SUMMARIZE or any other function that expects a table of values as a parameter. No, it is not resticted for sole use in CALCULATE but a lot of people seem to believe that is the case.



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...

@Greg_Deckler 

"For the sake of simplicity, we shorten that complex article into this best practice: never use ALLSELECTED inside an iteration."

 

AVERAGEX (
    ALL ( 'Product'[Brand] ),
    CALCULATE (
        [Margin %],
        ALLSELECTED ()
    )
)
 
It is not that ALLSELECTED would not work in this code snippet. The problem is that ALLSELECTED semantics are very complex, nearly beyond human comprehension. Therefore, you might obtain crazy numbers that are extremely complex to explain and most likely not the ones you were needing.
 

@PowerBITestingG You could say the same thing about CALCULATE in general. People say similar stuff about SUMMARIZE but it's like this 1 extremely specific situation where you might get some craziness. I don't worry about edge cases that you aren't going to run into in any conceivable situation.



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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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