cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
BenTooneyCS Frequent Visitor
Frequent Visitor

Count( if column value = string)

Hi,
Having trouble with DAX syntax in if statements for checking if a column's string value equals a certain value.

 

I want to do some calculations using different counts of strings, such as:

COUNT(IF(Table[Location] = "In Storage 1", 1, 0)) - COUNT(IF(Table[Location] = "Out Storage 1", 1, 0))

 

DateLocation
14/04/2019In Storage 1
14/04/2019In Storage 2
14/04/2019Out Storage 1
14/04/2019Out Storage 2
14/04/2019In Storage 1
14/04/2019In Storage 2
14/04/2019Out Storage 1
14/04/2019Out Storage 2
1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Count( if column value = string)

@BenTooneyCS add new measure with following expression

 

MyBalanceCount = 
CALCULATE( COUNTROWS( MyTable ), MyTable[Location] = "In Storage" ) -
CALCULATE( COUNTROWS( MyTable ), MyTable[Location] = "Out Storage" )





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

Proud to be a Datanaut! Appreciate your Kudos Smiley Happy
Feel free to email me with any of your BI needs.





2 REPLIES 2
Super User
Super User

Re: Count( if column value = string)

@BenTooneyCS add new measure with following expression

 

MyBalanceCount = 
CALCULATE( COUNTROWS( MyTable ), MyTable[Location] = "In Storage" ) -
CALCULATE( COUNTROWS( MyTable ), MyTable[Location] = "Out Storage" )





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

Proud to be a Datanaut! Appreciate your Kudos Smiley Happy
Feel free to email me with any of your BI needs.





suhasakole Frequent Visitor
Frequent Visitor

Re: Count( if column value = string)

Hi Ben,

Along with the above approach, you can try the following creating 2 calculated measure and then use those in creating a final measure. Hope this might help you.

CntRowsInStorage = CALCULATETABLE(ROW("rows",COUNT(Table[Location])),FILTER(ALL(Table[Location]),SEARCH("In Storage",Table1[Text],1,0)))

CntRowsOutStorage = CALCULATETABLE(ROW("rows",COUNT(Table[Location])),FILTER(ALL(Table[Location]),SEARCH("Out Storage",Table1[Text],1,0)))

FinalCount = CntRowsInStorage - CntRowsOutStorage

Helpful resources

Announcements
Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 308 members 3,388 guests
Please welcome our newest community members: