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

Calculate with distinct count and contains text

Hi

 

Im trying to do a distinct count of rows by a period finish date, on top of this i need one of the columns to CONTAIN the word "travel" so far i have got it working when i search for a specific word using the below DAX but cant figure out how to get it working when i need it to only contain certain text?

 

Measure = CALCULATE(DISTINCTCOUNT(Rate_Card_Daily_Time_Report[Period Finish]), Rate_Card_Daily_Time_Report[Activity] = "travel")
1 ACCEPTED SOLUTION

@moomarine quick way could be add another column by concatenate resource name and date to make it unique record, and then use that in distinct count

 

New Column = 
Table[Resource Name] & FORMAT( Table[Date Column], "YYYYMMDD" )

 

and your measure, in distinct count, use New Column 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

9 REPLIES 9
Mariusz
Community Champion
Community Champion

Hi @moomarine 

 

Try this

 

 

Measure = 
CALCULATE( 
    COUNTROWS( 
        GROUPBY( 
            Rate_Card_Daily_Time_Report, 
            Rate_Card_Daily_Time_Report[Period Finish],
            Rate_Card_Daily_Time_Report[Resource Name]
        ),
        KEEPFILTERS( 
            SEARCH( "travel", Rate_Card_Daily_Time_Report[Activity], 1, FALSE() )
        )
    )
)

 

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Mariusz
Community Champion
Community Champion

Hi @moomarine 

 

Try SEARCH function like below.

Measure = 
CALCULATE( 
    COUNTROWS( 'Table' ),
    KEEPFILTERS( 
        SEARCH( "travel", 'Table'[Commects], 1, FALSE() )
    )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Thanks for the help but the other solution worked well for me so didnt get a chance to test your one.

parry2k
Super User
Super User

@moomarine you can try something like this

 

Measure = 
CALCULATE(DISTINCTCOUNT(Rate_Card_Daily_Time_Report[Period Finish]), 
SEARCH("travel", Rate_Card_Daily_Time_Report[Activity], , -1 ) > 0
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi parry2k

 

That did work but has highlighted another issue for me. I have another column which is the resource full name. If the distinct value in column [period finish] has a different resource full name i need those to still be calculated. Not sure if that makes sence? So its only considered distinct if the resource full name matches.

@moomarine can you share sample data and explain what you are looking for .



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi sorry but cant share the file as its sensitive info. below is a screen shot. So in column [period finish] there is multiple 12 January 2019 which need to be counted as they have "travel" in column [activity] but if you look at the rows for resource name Jason he has 2 rows that are 12 January 2019, i need this to be considered a count of 1 for Jason as its a duplicate. but the total for what you see in photo would be 3 for 12 January 2019.

image001.png

@moomarine quick way could be add another column by concatenate resource name and date to make it unique record, and then use that in distinct count

 

New Column = 
Table[Resource Name] & FORMAT( Table[Date Column], "YYYYMMDD" )

 

and your measure, in distinct count, use New Column 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

This worked really well thanks you! My brain can stop hurting now!

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.