Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
IvanS
Helper V
Helper V

Remove row in calculated table based on CONCATENATE field

Hi guys,

 

in my data model I am calculating nr. of tasks where task owner can select team composition (unlimited nr. of people participating on task). Calculated table below is splitting 1 task ID into several rows if field Team Composition is not blank.

VAR _table = FILTER(Working time, Working time[ClosedTime]>BLANK())
RETURN
FILTER(
    DISTINCT(    
        UNION(
            SELECTCOLUMNS(_table,"Task ID", Working time[ID],"Close Date", Working time[ClosedTime],"Name", Working time[TaskOwner Name], "Task performed as", "Task Owner"),

            SELECTCOLUMNS(_table,"Task ID", Working time[ID],"Close Date", Working time[ClosedTime],"Name", Working time[TeamComposition], "Task performed as", "Team Composition")
        )
    ),
    [Name] <> BLANK()
)

 

However, I found cases where used accidentally put the same name (Task Owner = Team Composition) and such cases need to be filtered out from this table.


What I am trying to achieve is to remove duplicates and keep only distinct values for expression CONCATENATE( [ID], [Name]). Unfortunately I was not able to include it in my table calculate.

 

Any suggestions are much appreciated!


Thanks

Ivan

 

1 ACCEPTED SOLUTION

Based on your data it's better to do that in Power Query M than in DAX. It's less complex and gives you a flexibility.

 

This is a few steps how it could be done in Power Query M editor:

 

Oryginal Data:

bolfri_0-1673965229504.png

 

Step 1. Select "Team Composition" column and select from Ribbon > Transform > Split Column by Delimeter.

 

Selec or ener delimeter: --Custom--

Value: ", " <-- here is a coma AND SPACE (white character)

Split at: Each occurrence of the delimeter

and in Advanced options: Split into Rows

 

bolfri_1-1673965347522.png

 

Step 2. Create a new Custom Column that checks invalid inputs from user such us "TaskOwner"="Team Composition".

bolfri_2-1673965588073.png

 

Step 3. Tricky part. You can do that step in same query, but to show you the output I will use a new query and them Append the Queries, so you can track each step.

 

3. Power Query - multiple steps 🙂
#if you want, I can show you how to do that in same query

 

Table 1. Task Owners

 

We know that Task Owner should be an aggregation to get unique Owners per 

Create new Empty Query and use Power Query M groupping functions:

= Table.Group(Table, {"ID", "Close Time", "TaskOwner Name"},{})

bolfri_3-1673966169223.png

 

Rename column [TaskOwner Name] to [Name]

 

Then Add a new column "Task Performed as" with "Task Owner" value.

 

This is the result for: TaskOwner table.

bolfri_4-1673966444220.png

 

Full Power Query M for TaskOwner:

let
    Source = Table.Group(Table, {"ID", "Close Time", "TaskOwner Name"},{}),
    #"Rename column: TaskOwner Name to Name" = Table.RenameColumns(Source,{{"TaskOwner Name", "Name"}}),
    #"New column: Task Performed as" = Table.AddColumn(#"Rename column: TaskOwner Name to Name", "Task Performed as", each "Task Owner")
in
    #"New column: Task Performed as"

 

Table 2. Task Composition

 

To create second table we need to filter out rows with errors and then group them like before but this time with Team Composition.

 

Create new Empty Query and use Power Query M groupping functions:

= Table.Group(Table.SelectRows(Table, each ([Error Flag] <> true)), {"ID", "Close Time", "Team Composition"},{})

bolfri_5-1673966771591.png

 

Rename column [Team Composition] to [Name]

 

Then Add a new column "Task Performed as" with "Team Composition" value.

 

This is the result for: TaskComposition table.

bolfri_6-1673966936752.png

 

Full Power Query M for TaskComposition :

let
    Source = Table.Group(Table.SelectRows(Table, each ([Error Flag] <> true)), {"ID", "Close Time", "Team Composition"},{}),
    #"Rename column: Team Composition to Name" = Table.RenameColumns(Source,{{"Team Composition", "Name"}}),
    #"New column: Task Performed as" = Table.AddColumn(#"Rename column: Team Composition to Name", "Task Performed as", each "Team Composition")
in
    #"New column: Task Performed as"

Table 3. Combined Table by Append Queries as a New Query with two previous tables.

bolfri_7-1673967054296.png

let
    Source = Table.Combine({TaskOwner, TaskComposition})
in
    Source

 

Note that in all step(s) I've skipped changing type of fields. It's better to do that in the final table due to fact that you will do that once, not 3 times. 🙂

 

I hope that this will help you.

 

PBIX FILE:

https://we.tl/t-j6UlDwxJSD

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
bolfri
Super User
Super User

Some sample row(s) of your data would be nice and expected results based on that data. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @bolfri ,

please find below steps how the calculated table is created.

 

1. Original table

IDClose TimeTaskOwner NameTeam Composition 
11.1.2023User 1User 1/* error: TaskOwner Name = Team Composition */
231.1.2022User 2User 3, User 4 

 

2. Calculated table

IDClose TimeNameTask Performed as 
11.1.2023User 1Task Owner/* row has been split to 2 rows */
11.1.2023User 1Team Composition/* duplicated row */
231.1.2022User 2Task Owner 
231.1.2022User 3Team Composition 
231.1.2022User 4Team Composition 

 

Now as you can see - Task with ID have incorrectly inputed Team Composition with same name as TaskOwner name. Therefore, for these cases I need to remove this row and keep only that row where Task Performed as is "Task Owner".

 

Desired result is following:

IDClose TimeNameTask Performed as 
11.1.2023User 1Task Owner/* duplicated row removed */
231.1.2022User 2Task Owner 
231.1.2022User 3Team Composition 
231.1.2022User 4Team Composition 


Hope it is more clear now.

 

Thank you

Ivan

Based on your data it's better to do that in Power Query M than in DAX. It's less complex and gives you a flexibility.

 

This is a few steps how it could be done in Power Query M editor:

 

Oryginal Data:

bolfri_0-1673965229504.png

 

Step 1. Select "Team Composition" column and select from Ribbon > Transform > Split Column by Delimeter.

 

Selec or ener delimeter: --Custom--

Value: ", " <-- here is a coma AND SPACE (white character)

Split at: Each occurrence of the delimeter

and in Advanced options: Split into Rows

 

bolfri_1-1673965347522.png

 

Step 2. Create a new Custom Column that checks invalid inputs from user such us "TaskOwner"="Team Composition".

bolfri_2-1673965588073.png

 

Step 3. Tricky part. You can do that step in same query, but to show you the output I will use a new query and them Append the Queries, so you can track each step.

 

3. Power Query - multiple steps 🙂
#if you want, I can show you how to do that in same query

 

Table 1. Task Owners

 

We know that Task Owner should be an aggregation to get unique Owners per 

Create new Empty Query and use Power Query M groupping functions:

= Table.Group(Table, {"ID", "Close Time", "TaskOwner Name"},{})

bolfri_3-1673966169223.png

 

Rename column [TaskOwner Name] to [Name]

 

Then Add a new column "Task Performed as" with "Task Owner" value.

 

This is the result for: TaskOwner table.

bolfri_4-1673966444220.png

 

Full Power Query M for TaskOwner:

let
    Source = Table.Group(Table, {"ID", "Close Time", "TaskOwner Name"},{}),
    #"Rename column: TaskOwner Name to Name" = Table.RenameColumns(Source,{{"TaskOwner Name", "Name"}}),
    #"New column: Task Performed as" = Table.AddColumn(#"Rename column: TaskOwner Name to Name", "Task Performed as", each "Task Owner")
in
    #"New column: Task Performed as"

 

Table 2. Task Composition

 

To create second table we need to filter out rows with errors and then group them like before but this time with Team Composition.

 

Create new Empty Query and use Power Query M groupping functions:

= Table.Group(Table.SelectRows(Table, each ([Error Flag] <> true)), {"ID", "Close Time", "Team Composition"},{})

bolfri_5-1673966771591.png

 

Rename column [Team Composition] to [Name]

 

Then Add a new column "Task Performed as" with "Team Composition" value.

 

This is the result for: TaskComposition table.

bolfri_6-1673966936752.png

 

Full Power Query M for TaskComposition :

let
    Source = Table.Group(Table.SelectRows(Table, each ([Error Flag] <> true)), {"ID", "Close Time", "Team Composition"},{}),
    #"Rename column: Team Composition to Name" = Table.RenameColumns(Source,{{"Team Composition", "Name"}}),
    #"New column: Task Performed as" = Table.AddColumn(#"Rename column: Team Composition to Name", "Task Performed as", each "Team Composition")
in
    #"New column: Task Performed as"

Table 3. Combined Table by Append Queries as a New Query with two previous tables.

bolfri_7-1673967054296.png

let
    Source = Table.Combine({TaskOwner, TaskComposition})
in
    Source

 

Note that in all step(s) I've skipped changing type of fields. It's better to do that in the final table due to fact that you will do that once, not 3 times. 🙂

 

I hope that this will help you.

 

PBIX FILE:

https://we.tl/t-j6UlDwxJSD

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.