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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Slm584
New Member

trying to get unique value with result from IF statement

Hello,
trying to create new column with following if statement:

Contract Title = IF('table'[UCC_RO] = TRUE(), 'table'[Project_Title], 'table'[Contract_Title])
However, need to have (when True) table'[Project_Title] field unique only.
 
thank you all in advance,
 
Slm584
1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @Slm584 ,

If the 'unique only' represents the max/min value of the column, you can try this dax formula:

Contract Title = 
IF (
    'Table'[UCC_RO] = TRUE (),
    CALCULATE (
        MAX ( 'Table'[Project_Title] ),
        ALLEXCEPT ( 'Table', 'Table'[UCC_RO] )
    ),
    'Table'[Contract_Title]
)

vyingjl_0-1654741858246.png

 

If it represents like the first value of the column, you can try this query in Power Query Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclbSUSopKk0FUgEhhkDSGUjG6kQrOQLZaYk5xRAZI7CMEVjGCVOLMVjCFVnCGCxhApZwQTHLBCxjqhQbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, UCC_RO = _t, Project_Title = _t, Contract_Title = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"UCC_RO", type logical}, {"Project_Title", type text}, {"Contract_Title", type text}}),
    #"Grouped Rows" = 
        Table.Group(
            #"Changed Type", {"UCC_RO"}, 
            {
                {"Data", each 
                Table.AddIndexColumn(_,"Index",1), 
                type table [Category=nullable text, UCC_RO=nullable logical, Project_Title=nullable text, Contract_Title=nullable text, Index = nullable number]
                }
            }
        ),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Category", "Project_Title", "Contract_Title", "Index"}, {"Category", "Project_Title", "Contract_Title", "Index"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Data", "Custom", each if [UCC_RO] = true then Table.SelectRows(#"Expanded Data", each [Index] = 1 and [UCC_RO] = true)[Project_Title]{0} else [Contract_Title], type text),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Category", "UCC_RO", "Project_Title", "Contract_Title", "Custom"})
in
    #"Reordered Columns"

vyingjl_1-1654741965518.png

 

Best Regards,
Community Support Team _ Yingjie Li
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

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @Slm584 ,

If the 'unique only' represents the max/min value of the column, you can try this dax formula:

Contract Title = 
IF (
    'Table'[UCC_RO] = TRUE (),
    CALCULATE (
        MAX ( 'Table'[Project_Title] ),
        ALLEXCEPT ( 'Table', 'Table'[UCC_RO] )
    ),
    'Table'[Contract_Title]
)

vyingjl_0-1654741858246.png

 

If it represents like the first value of the column, you can try this query in Power Query Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclbSUSopKk0FUgEhhkDSGUjG6kQrOQLZaYk5xRAZI7CMEVjGCVOLMVjCFVnCGCxhApZwQTHLBCxjqhQbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, UCC_RO = _t, Project_Title = _t, Contract_Title = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"UCC_RO", type logical}, {"Project_Title", type text}, {"Contract_Title", type text}}),
    #"Grouped Rows" = 
        Table.Group(
            #"Changed Type", {"UCC_RO"}, 
            {
                {"Data", each 
                Table.AddIndexColumn(_,"Index",1), 
                type table [Category=nullable text, UCC_RO=nullable logical, Project_Title=nullable text, Contract_Title=nullable text, Index = nullable number]
                }
            }
        ),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Category", "Project_Title", "Contract_Title", "Index"}, {"Category", "Project_Title", "Contract_Title", "Index"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Data", "Custom", each if [UCC_RO] = true then Table.SelectRows(#"Expanded Data", each [Index] = 1 and [UCC_RO] = true)[Project_Title]{0} else [Contract_Title], type text),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Category", "UCC_RO", "Project_Title", "Contract_Title", "Custom"})
in
    #"Reordered Columns"

vyingjl_1-1654741965518.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

AlB
Community Champion
Community Champion

Hi @Slm584 

Can you show some sample data to illustrate what you are looking for? It's not quite clear now

Is it a calculated column or a measure? Is this in PQ or DAX?

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors