DAX/POWERPIVOT Count Number of Values That Contain Certain Text

melq64

New Member
Joined
Aug 21, 2017
Messages
49
Hi,

I've created this dax measure to count the number of values in a column that contain the text "PO BOX"

TotalPOBox:=COUNTROWS(FILTER('DistProfile v1-3',FIND("PO BOX",'DistProfile v1-3'[Dest_Address],,0)>0))

The formula works fine but the value returned (373) is less than the actual number of "PO BOX" values which should be (394).

Here's a sample of the column values in question:

PO BOX 300404
PO BOX 300712
PO BOX 106045
1 LINCOLN AVE
56 MARYLAND RD
33 LANCASTER RD
PO BOX 200453

I'm obviously missing something and would appreciate any assistance.


Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Too hard to say based on this. Create a table viz, put your lookup column in there and this measure in the values. Then sort by your values column and look for the rows where it returns zero, but you expect a match. Then investigate those.
 
Upvote 0
Chose the table name "Table1" and used SEARCH instead of FIND (SEARCH is not case sensitive):

Code:
=CALCULATE (
    COUNTROWS ( Table1 ),
    FILTER ( Table1, SEARCH ( "PO BOX", Table1[Address], 1, 0 ) > 0 )
 
Upvote 0
Perfect thank you brawnystaff. That worked:)

If its ok to ask for assistance regarding same measure, is it possible to search for the FIRST NUMBER only of zipcodes? e.g. search "0","1","2","3" Example below:

0610
0932
0743
1432
1338
2025
2088
3097
4122
 
Upvote 0
Assuming zip codes were in their own cell, for one value at at time, it would be as follows:

Code:
=CALCULATE(COUNTROWS ( Table1 ),FILTER( Table1,If( LEFT(Table1[Zip],1)="1",1, 0 ) > 0 ))

However, it looking to count based on a range of first numbers, it would be as follows:

Code:
=CALCULATE(COUNTROWS ( Table1 ),FILTER( Table1,If( LEFT(Table1[Zip],1)="0"||LEFT(Table1[Zip],1)="1"||LEFT(Table1[Zip],1)="2"||LEFT(Table1[Zip],1)="3",1, 0 ) > 0 ))
 
Upvote 0
Yes you right about the correct count. I was hoping you could replicate my issue with the full dataset. When I input the formula into powerpivot data model, the count total is different as mentioned earlier. I doubled checked that filters were turned off so not sure why incorrect count total...perhaps I'm missing something else?

Here's the actual formula in my datamodel with count total returned (1745)

TotalItemsForAMC:=CALCULATE(COUNTROWS ( 'DistProfile v1-3'),FILTER('DistProfile v1-3',If( LEFT('DistProfile v1-3'[Origin_Postcode],1)="0"||LEFT('DistProfile v1-3'[Origin_Postcode],1)="1"||LEFT('DistProfile v1-3'[Origin_Postcode],1)="2"||LEFT('DistProfile v1-3'[Origin_Postcode],1)="3",1, 0 ) > 0 ))
 
Upvote 0
Sorry to bug you again brawnystaff but do you have any suggestions on what the issue could be regarding my last post? Would appreciate any feedback. Thanks:)
 
Upvote 0
Hard to say...although I note that your formatting in cells is inconsistent, as although it says "General" for all, some numbers appear to be formatted as Text (justification to left instead of right).

Perhaps another way to handle this is assuming that helper column "prefix" will be present, utilize that field to do the analysis (as well as shorten the formula). Using the prefix column as part of the table, the DAX formula would be as follows:

Code:
=CALCULATE(COUNTROWS ( Table1 ),FILTER( Table1,If(Table1[prefix]="0"||Table1[prefix]="1"||Table1[prefix]="2"||Table1[prefix]="3",1, 0 ) > 0 ))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top