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
CosmicHorse95
Advocate I
Advocate I

DAX to sum specific rows in a column

I have a table with [State], [#Samples], [#Positive], and [#Negative] Columns.

 

I'm trying to create a DAX that will add up all of the [#Negative] for each state.

In other words, I basically need AlabamaNegSamples=[#Negative] if [State]=Alabama

But I'm not sure how to write that in DAX language.

 

Thank you in advance!
StateScreenshot.jpg

 

1 ACCEPTED SOLUTION

@CosmicHorse95 

Measure = SUMX(FILTER('Table',[State]="Alabama"),VALUE([#Negative]))

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
Greg_Deckler
Super User
Super User

@CosmicHorse95 Try:

Measure = 
  SUMX(SUMMARIZE('Table',[State],"__Neg",SUM([#Negative])),[__Neg])

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler I got the following error message (see picture)

Did you mean to list "__Neg" or was I supposed to change that to "#Neg" as that's the name of the column?Error Message.png

 

@CosmicHorse95 Try changing your Data Type for that column to Whole number or:

Measure = 
  SUMX(SUMMARIZE('Table',[State],"__Neg",SUM(VALUE[#Negative]))),[__Neg]

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

Ok so changing the Data Type to a whole number helped, and the DAX is "valid" but the calculation is wrong. It should only be 15, but it calculated 89...

89 is the grand total for all negative samples for all states, but I'm trying to have a Measurement for the Total of Negative Samples for Each state.

@CosmicHorse95 So normally you would just put State in a table visual or other visual and then use a simple SUM of [#Negative] column for that.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

I'm sorry, I don't think I understand. I got this far, but I don't need the grand total, as I already have that. I'm trying to explain what I need a different way, I'm sorry if I'm not being clear enough.

Alabama has 2 negative samples. I need a measure that will give me the total of just the Alabama negative samples. When I use the SUM function, it sums the entire column, and i do not want that.State Pos Neg Totals.png

 

@CosmicHorse95 

Measure = SUMX(FILTER('Table',[State]="Alabama"),VALUE([#Negative]))

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

It works! Thank you so so much!!!!

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.

Top Solution Authors