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

Display only first column value in a table with duplicate values

Good day!

 

I am trying to figure out how to show only the first value of the column. I have a table that contains duplicate values for InvoiceID and InvoiceAmount for each productID. I want to keep the InvoiceID column with all it's values, but the InvoiceAmount should only display the first value, basically I want to get rid of the duplicate value using the measure.

Example:

 

InvoiceID InvoiceAmount productID
A0246605 999999 item0010
A0246605 999999 Item0079
A0246605 999999 Item0081
A0246605 999999 Item0093
A0246605 999999 Item0166
A0246605 999999 Item0191
A0246605 999999 Item0102
A0246605 999999 Item0470
A0246605 999999 Item0001

 

The result  I am looking for:

 

InvoiceID InvoiceAmount productID
A0246605 999999 item0010
A0246605               Item0079
A0246605               Item0081
A0246605             Item0093
A0246605             Item0166
A0246605             Item0191
A0246605             Item0102
A0246605             Item0470
A0246605             Item0001

 

Thanks in advance!

 

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

hi  @RuslanP1 

If you want to create a measure, just try this measure

Measrue = 
var _firstrow=CALCULATE(MIN('Table'[productID]),ALLEXCEPT('Table','Table'[InvoiceID],'Table'[InvoiceAmount])) 
return
CALCULATE(MIN('Table'[InvoiceAmount]),FILTER('Table','Table'[productID]=_firstrow))

Result:

3.JPG

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
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

5 REPLIES 5
v-lili6-msft
Community Support
Community Support

hi  @RuslanP1 

If you want to create a measure, just try this measure

Measrue = 
var _firstrow=CALCULATE(MIN('Table'[productID]),ALLEXCEPT('Table','Table'[InvoiceID],'Table'[InvoiceAmount])) 
return
CALCULATE(MIN('Table'[InvoiceAmount]),FILTER('Table','Table'[productID]=_firstrow))

Result:

3.JPG

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
swise001
Continued Contributor
Continued Contributor

@RuslanP1 

 

Here's a solution using Power Query and your sample data table: 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQwMjEzMzBVsAQDhcyS1FwDA0MDpVgdTElPsKS5JR5JC0M8kpbGuCUNzczwSFriMdbQwAi3pIk5Pq8YAI2NBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"InvoiceID InvoiceAmount productID" = _t]),
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "InvoiceID InvoiceAmount productID", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"InvoiceID InvoiceAmount productID.1", "InvoiceID InvoiceAmount productID.2", "InvoiceID InvoiceAmount productID.3"}),
    #"Renamed Columns" = Table.RenameColumns(#"Split Column by Delimiter",{{"InvoiceID InvoiceAmount productID.1", "InvoiceID"}, {"InvoiceID InvoiceAmount productID.2", "InvoiceAmount"}, {"InvoiceID InvoiceAmount productID.3", "productID"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"InvoiceAmount", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"InvoiceID"}, {{"All", each _, type table [InvoiceID=nullable text, InvoiceAmount=nullable number, productID=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "WithIndex", each Table.AddIndexColumn([All],"Index",1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"WithIndex"}),
    #"Expanded WithIndex" = Table.ExpandTableColumn(#"Removed Other Columns", "WithIndex", {"InvoiceID", "InvoiceAmount", "productID", "Index"}, {"InvoiceID", "InvoiceAmount", "productID", "Index"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded WithIndex", "Invoice Amount", each if [Index] = 1 then [InvoiceAmount] else ""),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"InvoiceAmount", "Index"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"InvoiceID", "Invoice Amount", "productID"})
in
    #"Reordered Columns"

swise001_0-1599660062754.png

 

Just Copy Paste this into the Advanced Editor for a new query.  A similar pattern could be applied to your table.   

amitchandak
Super User
Super User

@RuslanP1 , See if these measures can help

 

sumx(values(Table[InvoiceID]), min(Table[InvoiceAmount]))

sumx(values(Table[InvoiceID]),Firstnonblankvalue(productID, min(Table[InvoiceAmount])))

Thank you for the quick reply @amitchandak

I checked the suggested measures and both of them returned the same InvoiceAmount for each row:

 

InvoiceIDproductIDMeasureMeasure 3InvoiceAmount
A0246605item0010999999 999999 999999 
A0246605Item0079999999 999999 999999 
A0246605Item0081999999 999999 999999 
A0246605Item0093999999 999999 999999 
A0246605Item0166999999 999999 999999 
A0246605Item0191999999 999999 999999 
A0246605Item0102999999 999999 999999 
A0246605Item0470999999 999999 999999 
A0246605Item0001999999 999999 999999 

 

Measure "Measure" - sumx(values(Table[InvoiceID]), min(Table[InvoiceAmount]))

Measure "Measure 3" - sumx(values(Table[InvoiceID]),Firstnonblankvalue(productID, min(Table[InvoiceAmount])))

 

@RuslanP1 Is there something to identify "First" like a date column or Index? Index would be good then it would be easy. Just find the MINX at that point. Basically a Lookup Min/Max. https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.