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
chat_peters
Helper III
Helper III

How to create a measure to count all the rows a text is contained in

Hello,

 

I have a simple data model and in my only fact table I have a column for buyer location and caller location. And I have another column where I concatenated the two columns. What I want to be able to do is to count all the rows for a select caller location if the concatenated column contains that selected value. This is the end result I want to achieve.  I can't use IN operator or USERELATIONSHIP (The actual model is quite large and we are on direct query in SSAS. Adding calculated tables are also not  supported. Is there anyway to achieve this with dax without having to make tables in the SQL server. Link to the file PowerBI File 

When I select Caller Location Guadalajara I want it to look in the concat column and count that row if it's in the concat column. 

thank you for taking the time to read this post

 

1.PNG

 

1 ACCEPTED SOLUTION
chat_peters
Helper III
Helper III

I tried this

Measurecontainsstring = Var locations_x = SELECTEDVALUE(CallerDim[Caller Location])

                                         RETURN CALCULATE(
                                         COUNTROWS(
                                         FILTER(orderfact, CONTAINSSTRING(orderfact[concatcol],locations_x))),
ALL(Caller))

 

 

 

View solution in original post

7 REPLIES 7
chat_peters
Helper III
Helper III

@m3tr01d I found out that I can't use containsstring function in SSAS directquery mode. I wrote this function below. However, it's not summing up the values correctly. Do you have any suggestions on how I can make this measure work?

Totalordersnew = var locations = IF(HASONEVALUE(CallerDim[Caller location]),VALUES(CallerDim[Caller location]))
                                RETURN CALCULATE(
                                            COUNTROWS(
                                                    FILTER('Order Fact',
                                                        OR(locations='Order Fact'[Caller Location],
                                                           locations='Order Fact'[Buyer Location]))),
                                                            All(CallerDim))
chat_peters
Helper III
Helper III

I tried this, and it solved my problem. Thank you for pointing me in the right direction 🙂

Measurecontainsstring = Var locations_x = SELECTEDVALUE(CallerDim[Caller Location])

                                         RETURN CALCULATE(
                                         COUNTROWS(
                                         FILTER(orderfact, CONTAINSSTRING(orderfact[concatcol],locations_x))),
ALL(Caller))
chat_peters
Helper III
Helper III

I tried this

Measurecontainsstring = Var locations_x = SELECTEDVALUE(CallerDim[Caller Location])

                                         RETURN CALCULATE(
                                         COUNTROWS(
                                         FILTER(orderfact, CONTAINSSTRING(orderfact[concatcol],locations_x))),
ALL(Caller))

 

 

 

chat_peters
Helper III
Helper III

@m3tr01d If someone selects caller location = Rio from slicer, I want to be able to count all the rows where concat column contains Rio. The measure should be able to count order IDs 11, 14, 4 and 7. The answer should be 4. 

m3tr01d
Continued Contributor
Continued Contributor

Ok, I see.

If you use a slicer with Caller location coming from the CallerDim, this measure should give you what you want :

Buyer_Count = 
--Grab the selected Caller location from the slicer
VAR _Selected = SELECTEDVALUE( 'CallerDim'[Caller location] )

RETURN
CALCULATE(
    COUNTROWS( 'Order Fact' ),
    'Order Fact'[Buyer Location] = _Selected,
    ALL( 'CallerDim' )
)

Thank you for your quick response and thank you for taking the time to post a solutions. The measure works partially. I want to be able to pull all the row where the buyer or the caller responds to the selected location in caller dim. Right now for Rio it's only pulling up 2 records where the Buyer is from Rio. (it's only pulling up order ID 11 and 14 from the above picture not order IDs 4 and 7)

m3tr01d
Continued Contributor
Continued Contributor

Hi @chat_peters 

I just want to make sure I understand what you are trying to do.
If someone selects Caller Location = Rio from a Slicer, you want to count all the orders where
Caller Location is different then Rio and Buyer Location is equal to Rio. Is it right?


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