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
kopilashvili
Microsoft Employee
Microsoft Employee

Returning unique values and combining the results

Hello,

 

i'm trying to create a column, which would return one of two value: if there is a value only in one of the columns, then it would retern name of that column, if there are values in more than one column, then it would return different value . For example, for 1st line, as there are values in two columnts Apples and Oranges, the output is combined - "Fruits"; for second line, since there is value only for Apples, the output should be "Apples" 

 

IndexApplesBananasOrangesPlumsOutput
1Yes Yes Fruits
2Yes   Apples
3 Yes  Bananas
4Yes Yes Fruits
5   YesPlums
      

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @kopilashvili 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

You may create a calculated column or a measure as below.

Calculated column:

Output Column = 
var tab = {[Apples],[Bananas],[Oranges],[Plums]}
var _count = 
COUNTROWS(
    FILTER(
        tab,
        [Value]="Yes"
    )
)
return
SWITCH(
    TRUE(),
    _count=1,
    SWITCH(
        TRUE(),
        [Apples]="Yes","Apples",
        [Bananas]="Yes","Bananas",
        [Oranges]="Yes","Oranges",
        [Plums]="Yes","Plums"
    ),
    _count>1,"Fruits"
)

 

Measure:

Output Measure = 
var _apples=SELECTEDVALUE('Table'[Apples])
var _bananas=SELECTEDVALUE('Table'[Bananas])
var _oranges=SELECTEDVALUE('Table'[Oranges])
var _plums=SELECTEDVALUE('Table'[Plums])
var tab = {_apples,_bananas,_oranges,_plums}
var _count = 
COUNTROWS(
    FILTER(
        tab,
        [Value]="Yes"
    )
)
return
SWITCH(
    TRUE(),
    _count=1,
    SWITCH(
        TRUE(),
        _apples="Yes","Apples",
        _bananas="Yes","Bananas",
        _oranges="Yes","Oranges",
        _plums="Yes","Plums"
    ),
    _count>1,"Fruits"
)

 

Result:

b2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-alq-msft
Community Support
Community Support

Hi, @kopilashvili 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

You may create a calculated column or a measure as below.

Calculated column:

Output Column = 
var tab = {[Apples],[Bananas],[Oranges],[Plums]}
var _count = 
COUNTROWS(
    FILTER(
        tab,
        [Value]="Yes"
    )
)
return
SWITCH(
    TRUE(),
    _count=1,
    SWITCH(
        TRUE(),
        [Apples]="Yes","Apples",
        [Bananas]="Yes","Bananas",
        [Oranges]="Yes","Oranges",
        [Plums]="Yes","Plums"
    ),
    _count>1,"Fruits"
)

 

Measure:

Output Measure = 
var _apples=SELECTEDVALUE('Table'[Apples])
var _bananas=SELECTEDVALUE('Table'[Bananas])
var _oranges=SELECTEDVALUE('Table'[Oranges])
var _plums=SELECTEDVALUE('Table'[Plums])
var tab = {_apples,_bananas,_oranges,_plums}
var _count = 
COUNTROWS(
    FILTER(
        tab,
        [Value]="Yes"
    )
)
return
SWITCH(
    TRUE(),
    _count=1,
    SWITCH(
        TRUE(),
        _apples="Yes","Apples",
        _bananas="Yes","Bananas",
        _oranges="Yes","Oranges",
        _plums="Yes","Plums"
    ),
    _count>1,"Fruits"
)

 

Result:

b2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @v-alq-msft Allan - this worked well for me! 

Fowmy
Super User
Super User

 

@kopilashvili 

Paste this in a blank query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUYpMLQaSCigst6LSzJJipVidaCUjFAkYdiwoyEmFKDDG0A3CTol5QAhRYULYFlM08yGKAnJKc4HysQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, Apples = _t, Bananans = _t, Oranges = _t, Plums = _t, Output = _t]),
    #"Removed Columns" = Table.RemoveColumns(Source,{"Output"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Index"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] = "Yes")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Index"}, {{"Count", each _, type table [Index=nullable text, Attribute=text, Value=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each if List.Count([Count][Value]) > 1 then "Fruits" else [Count][Attribute]{0}),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Merged Queries" = Table.NestedJoin(Source, {"Index"}, #"Removed Columns1", {"Index"}, "Removed Columns1", JoinKind.LeftOuter),
    #"Expanded Removed Columns1" = Table.ExpandTableColumn(#"Merged Queries", "Removed Columns1", {"Custom"}, {"Custom"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Removed Columns1",{{"Custom", "New Output"}})
in
    #"Renamed Columns"

Fowmy_0-1596293880713.png

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thank you @Fowmy just curious, if there is a way to solve it without coding / json? 

@kopilashvili 

No Code solution :

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUYpMLQaSCigst6LSzJJipVidaCUjFAkYdiwoyEmFKDDG0A3CTol5QAhRYULYFlM08yGKAnJKc4HysQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, Apples = _t, Bananans = _t, Oranges = _t, Plums = _t, Output = _t]),
    #"Removed Columns" = Table.RemoveColumns(Source,{"Output"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Index"}, "Attribute", "Value"),
    #"Added Conditional Column" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each if [Value] = "Yes" then [Attribute] else null),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Conditional Column",{"Value"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns1", List.Distinct(#"Removed Columns1"[Attribute]), "Attribute", "Custom"),
    #"Inserted Merged Column" = Table.AddColumn(#"Pivoted Column", "Merged", each Text.Combine({[Plums], [Oranges], [Bananans], [Apples]}, "="), type text),
    #"Added Conditional Column1" = Table.AddColumn(#"Inserted Merged Column", "New Output", each if Text.Contains([Merged], "=") then "Fruits" else [Merged]),
    #"Removed Columns2" = Table.RemoveColumns(#"Added Conditional Column1",{"Merged"})
in
    #"Removed Columns2"

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@kopilashvili 

I need to try and get back to you 🙂

Thanks
Fowmy

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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