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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Group by columns in DAX

Hi All,

 

I had an input table which looked like this

 

Anchor DealerTarget DealerRevenue
Dealer1:Dealer2Dealer2:Dealer3

124

 

 

And output table which has extra Compare value which will be either Yes or No for each combination of Anchor Dealer and Target Dealer. The issue after splitting Anchor Dealer and Target Dealer are that now I get 4 rows for 1 row of Revenue i.e revenue is counted 4 times in my Table

 

 

Anchor DealerTarget DealerCompare ValueRevenue
Dealer1Dealer2Yes124
Dealer1Dealer3Yes124
Dealer2Dealer2Yes124
Dealer2Dealer3Yes124

 

 

I don't want to do a revenue/4 type of solution. Can you please guide on how to get the output like below:

 

Anchor DealerTarget DealerRevenueCompare Value
Dealer1:Dealer2Dealer2:Dealer3124Yes
1 ACCEPTED SOLUTION

Alright interesting case! I came up with the following solution.

Step 1: Dubplicate the anchor column and split the duplicate column by delimiter, in this case by semi-column. I created a practice table with more than 2 anchors per row, so I got more columns than 2. I don't know how many anchors you can have in that column per row, but I didn't think it would be a maximum of 2.

My original test tableMy original test tableDuplicated the Anchor columnDuplicated the Anchor columnSplitting by delimiter created 4 additional columnsSplitting by delimiter created 4 additional columns

Step two is to create a custom column that checks if the Target column contains any of the values. THis is the formula I used:

if Text.Contains([Targets], Text.From([#"Anchors - Copy.1"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.2"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.3"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.4"])) then "yes" else "no"

This results in another column with "yes" or "error". The errors are because for some reason I couldn't compare a text value (Targets) with null values, see my third screenshot. You can replace errors by 'no' by right clicking on the new column and click 'Replace errors' and replace it with 'no'./ Then remove all columns you don't need anymore (the duplicate, all delimited columns) and you are left with this:

image.png

Here my total M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSrROsk5W0lFKsk5RitUB8cuAvFTrNCgvyTrNOh0okmidbp0KEwOrT0bipYDkYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Anchors"}, {"Column2", "Targets"}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Renamed Columns", "Anchors", "Anchors - Copy"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Duplicated Column", "Anchors - Copy", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Anchors - Copy.1", "Anchors - Copy.2", "Anchors - Copy.3", "Anchors - Copy.4"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Targets", type text}, {"Anchors - Copy.1", type text}, {"Anchors - Copy.2", type text}, {"Anchors - Copy.3", type text}, {"Anchors - Copy.4", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each if Text.Contains([Targets], Text.From([#"Anchors - Copy.1"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.2"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.3"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.4"])) then "yes" else "no"),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom", {{"Custom", "no"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Replaced Errors",{"Anchors - Copy.1", "Anchors - Copy.2", "Anchors - Copy.3", "Anchors - Copy.4"})
in
    #"Removed Columns"

 

Hope this helps! That was fun to do 🙂

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Kudo's are welcome 🙂





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

Proud to be a Super User!




View solution in original post

5 REPLIES 5
JarroVGIT
Resident Rockstar
Resident Rockstar

If this is your input table:

Anchor DealerTarget DealerRevenue
Dealer1:Dealer2Dealer2:Dealer3

124

And your desired table is this:

Anchor DealerTarget DealerRevenueCompare Value
Dealer1:Dealer2Dealer2:Dealer3124Yes

You'll have to explain when the compare value is YES and when it should be NO?

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Kudo's are welcome 🙂





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

Proud to be a Super User!




Anonymous
Not applicable

Yes, your assumptions about input and output table is correct.

 

Your question on how compare value is derived:

 

There is another column called F value which compares anchor dealer and target dealer.

If they are equal then its a Yes or else No

 

Now compare value becomes Yes if there is at least one Yes for anchor and target dealer combination

else it becomes a No. 

 

I have not added Fvalue to avoid confusion

Bottom line is for each anchor and target dealer combination there will be either a  Yes or No

Alright interesting case! I came up with the following solution.

Step 1: Dubplicate the anchor column and split the duplicate column by delimiter, in this case by semi-column. I created a practice table with more than 2 anchors per row, so I got more columns than 2. I don't know how many anchors you can have in that column per row, but I didn't think it would be a maximum of 2.

My original test tableMy original test tableDuplicated the Anchor columnDuplicated the Anchor columnSplitting by delimiter created 4 additional columnsSplitting by delimiter created 4 additional columns

Step two is to create a custom column that checks if the Target column contains any of the values. THis is the formula I used:

if Text.Contains([Targets], Text.From([#"Anchors - Copy.1"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.2"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.3"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.4"])) then "yes" else "no"

This results in another column with "yes" or "error". The errors are because for some reason I couldn't compare a text value (Targets) with null values, see my third screenshot. You can replace errors by 'no' by right clicking on the new column and click 'Replace errors' and replace it with 'no'./ Then remove all columns you don't need anymore (the duplicate, all delimited columns) and you are left with this:

image.png

Here my total M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSrROsk5W0lFKsk5RitUB8cuAvFTrNCgvyTrNOh0okmidbp0KEwOrT0bipYDkYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Anchors"}, {"Column2", "Targets"}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Renamed Columns", "Anchors", "Anchors - Copy"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Duplicated Column", "Anchors - Copy", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Anchors - Copy.1", "Anchors - Copy.2", "Anchors - Copy.3", "Anchors - Copy.4"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Targets", type text}, {"Anchors - Copy.1", type text}, {"Anchors - Copy.2", type text}, {"Anchors - Copy.3", type text}, {"Anchors - Copy.4", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each if Text.Contains([Targets], Text.From([#"Anchors - Copy.1"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.2"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.3"])) then "yes" else if Text.Contains([Targets], Text.From([#"Anchors - Copy.4"])) then "yes" else "no"),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom", {{"Custom", "no"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Replaced Errors",{"Anchors - Copy.1", "Anchors - Copy.2", "Anchors - Copy.3", "Anchors - Copy.4"})
in
    #"Removed Columns"

 

Hope this helps! That was fun to do 🙂

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Kudo's are welcome 🙂





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

Proud to be a Super User!




Anonymous
Not applicable

Wow, Thanks for spending so much time on this.

I'll try this. I thought it would be an easier thing to do. Thanks a lot

 

No problem, this forum is where people help each other 🙂 Just don't forget to like and mark as the solution!

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Kudo's are welcome 🙂





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

Proud to be a Super User!




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors