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
IgorGershenson
Helper II
Helper II

Sumif equivalents in DAX for calculated columns

I want to create two calculated columns in my data. I want the first one to show the number of sites for each hospital system and the second to show the total number clients in that system. Here is a simple example below. In Excel I would use Sumif to create the last two columns but how do I do it using DAX for calculated columns. I need these columns to create additional columns and measures later on.  Please help.

Health SystemSitesCount of SitesCustomer StatusCount of customersTotal Number of Sites in Health SystemTotal Number of Customers in Health System
UMASSsite 11YES185
UMASSsite 21NO085
UMASSsite 31YES185
UMASSsite 41YES185
UMASSsite 51NO085
UMASSsite 61YES185
UMASSsite 71YES185
UMASSsite 81NO085
NYUsite A1YES143
NYUsite B1YES143
NYUsite C1NO043
NYUsite D1YES143
2 ACCEPTED SOLUTIONS
Nathaniel_C
Super User
Super User

Tot Num Customer = CALCULATE(COUNT(Health[Customer Status]),ALLEXCEPT(Health,Health[Health System]),Health[Customer Status] = "YES")



Tot Num of Sites = CALCULATE(Count(Health[Health System]),ALLEXCEPT(Health,Health[Health System]))

Tot num.PNG

Hi @IgorGershenson ,

I did these as measures, so you can drop them on the visual.  They match what you have posted.  Thanks for the clarity in your posting! The CALCULATE allows this measure to iterate through the whole table, and the ALLEXCEPT keeps the one variable the same. 

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

AlB
Super User
Super User

Hi @IgorGershenson 

 

Total Number of Sites in Health System =
CALCULATE (
    DISTINCTCOUNT ( Table1[ Sites] ),
    ALLEXCEPT ( Table1, Table1[Health System] )
)

 

Total Number of Customers in Health System =
CALCULATE (
    SUM ( Table1[ Count of Customers] ),
    ALLEXCEPT ( Table1, Table1[Health System] )
)

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

 

View solution in original post

2 REPLIES 2
AlB
Super User
Super User

Hi @IgorGershenson 

 

Total Number of Sites in Health System =
CALCULATE (
    DISTINCTCOUNT ( Table1[ Sites] ),
    ALLEXCEPT ( Table1, Table1[Health System] )
)

 

Total Number of Customers in Health System =
CALCULATE (
    SUM ( Table1[ Count of Customers] ),
    ALLEXCEPT ( Table1, Table1[Health System] )
)

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

 

Nathaniel_C
Super User
Super User

Tot Num Customer = CALCULATE(COUNT(Health[Customer Status]),ALLEXCEPT(Health,Health[Health System]),Health[Customer Status] = "YES")



Tot Num of Sites = CALCULATE(Count(Health[Health System]),ALLEXCEPT(Health,Health[Health System]))

Tot num.PNG

Hi @IgorGershenson ,

I did these as measures, so you can drop them on the visual.  They match what you have posted.  Thanks for the clarity in your posting! The CALCULATE allows this measure to iterate through the whole table, and the ALLEXCEPT keeps the one variable the same. 

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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