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
Bertenvanloover
Frequent Visitor

How to Count rows that contain certain text string and current cell value

Hi, I could use some help finding a way to do the manipulation below in Power Query:
I want to create a custom column "Times_Edited" that counts the total times a Filename got "Change Editing Required" or "Editing Required".

 

I tried this one, but I presume that my [Filename]=[Filename] is the culprit.
= Table.AddColumn(#"Replaced Value1", "Times_Edited", each Table.RowCount(Table.FromRecords({[TransitionName] = "Change Editing Required" || [TransitionName] = "Editing Required" ,[Filename]=[Filename]})))


Purpose: this table shows a history log of changes to the status of Documents. This column would be used as a metric on how often a file is send back for editing. (potentially a DAX procedure is a better choice in comparison to a separate column?)

Thanks!!

 

Related to:
https://community.powerbi.com/t5/Power-Query/How-to-find-text-from-list-in-cell-and-return-that-text...

https://community.powerbi.com/t5/Power-Query/Find-Text-from-List-in-Rows-with-same-ID-as-current-row... 

 

FilenameTransitionNameSubmittedDateTimes_Edited
1Send for Approval22/02/2023 11:001
1Change Editing Required22/02/2023 11:011
1Approved22/02/2023 11:021
2Send for Approval22/02/2023 11:050
2Approved22/02/2023 11:060
3Send for Approval22/02/2023 11:003
3Editing Required22/02/2023 11:023
3Send for Approval22/02/2023 11:033
3Change Editing Required22/02/2023 11:053
3Approved22/02/2023 11:103
3Change Editing Required11/09/2023 09:113
1 ACCEPTED SOLUTION
6677028
Frequent Visitor

Send You.

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Removed Columns" = Table.RemoveColumns(Source,{"Times_Edited"}),
#"Added Custom" = Table.AddColumn(#"Removed Columns", "Custom", each if[TransitionName] ="Change Editing Required" or [TransitionName]= "Editing Required" then 1 else 0),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Filename"}, {{"Count", each List.Sum([Custom]), type number}}),
#"Merged Queries" = Table.NestedJoin(#"Removed Columns", {"Filename"}, #"Grouped Rows", {"Filename"}, "Removed Columns", JoinKind.FullOuter),
#"Expanded Removed Columns" = Table.ExpandTableColumn(#"Merged Queries", "Removed Columns", {"Filename", "Count"}, {"Filename.1", "Count"}),
#"Removed Columns1" = Table.RemoveColumns(#"Expanded Removed Columns",{"Filename.1"})
in
#"Removed Columns1"

View solution in original post

1 REPLY 1
6677028
Frequent Visitor

Send You.

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Removed Columns" = Table.RemoveColumns(Source,{"Times_Edited"}),
#"Added Custom" = Table.AddColumn(#"Removed Columns", "Custom", each if[TransitionName] ="Change Editing Required" or [TransitionName]= "Editing Required" then 1 else 0),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Filename"}, {{"Count", each List.Sum([Custom]), type number}}),
#"Merged Queries" = Table.NestedJoin(#"Removed Columns", {"Filename"}, #"Grouped Rows", {"Filename"}, "Removed Columns", JoinKind.FullOuter),
#"Expanded Removed Columns" = Table.ExpandTableColumn(#"Merged Queries", "Removed Columns", {"Filename", "Count"}, {"Filename.1", "Count"}),
#"Removed Columns1" = Table.RemoveColumns(#"Expanded Removed Columns",{"Filename.1"})
in
#"Removed Columns1"

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
Top Kudoed Authors