cancel
Showing results for
Search instead for
Did you mean:
Highlighted
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))

 Date Location 14/04/2019 In Storage 1 14/04/2019 In Storage 2 14/04/2019 Out Storage 1 14/04/2019 Out Storage 2 14/04/2019 In Storage 1 14/04/2019 In Storage 2 14/04/2019 Out Storage 1 14/04/2019 Out Storage 2
1 ACCEPTED SOLUTION

Accepted Solutions
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
Feel free to email me with any of your BI needs.

2 REPLIES 2
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
Feel free to email me with any of your BI needs.

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

Get your latest community news and announcements.

Power Platform Summit North America

Register by September 5 to save \$200

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.

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Kudoed Authors
Users Online
Currently online: 308 members 3,388 guests
Recent signins:
Please welcome our newest community members: