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

Need to tag Original duplicate in dax function

Need to tag Original duplicate in dax function, example below, thanks in advance.

req.PNG

2 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@balajir98 

I cannot think of a solution in DAX for this problem.
You need a supporting column that identifies the order/sort, I added an index column and completed it in Power Query itself. 

Fowmy_0-1621670686061.png

Paste the below code on a new blank query in the Advanced Editor and see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLSNTDVNTJU0lEyNFCK1aGiiDFcxIjKIiZwEWOyRWIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Int64.Type}},"en-gb"),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Count", each _, type table [Date=nullable date, Value=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1) ),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Date", "Value", "Index"}, {"Date", "Value", "Index"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded Custom", "Custom", each if [Index] = 1 then "Original" else "Duplicate"),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Index"})
in
    #"Removed Columns"

 

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

View solution in original post

v-angzheng-msft
Community Support
Community Support

Hi, @balajir98 

Add a index column in Power Query, then try to create a measure like below:

_Tag =
IF (
    CALCULATE (
        COUNT ( 'Table'[Date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Date], 'Table'[Value] ),
            [Index] <= MAX ( [Index] )
        )
    ) = 1,
    "Original",
    "Duplicate"
)

Result:

v-angzheng-msft_0-1621919396820.png

 

 

Best Regards,
Community Support Team _ Zeon Zheng
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-angzheng-msft
Community Support
Community Support

Hi, @balajir98 

Add a index column in Power Query, then try to create a measure like below:

_Tag =
IF (
    CALCULATE (
        COUNT ( 'Table'[Date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Date], 'Table'[Value] ),
            [Index] <= MAX ( [Index] )
        )
    ) = 1,
    "Original",
    "Duplicate"
)

Result:

v-angzheng-msft_0-1621919396820.png

 

 

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

 

Fowmy
Super User
Super User

@balajir98 

I cannot think of a solution in DAX for this problem.
You need a supporting column that identifies the order/sort, I added an index column and completed it in Power Query itself. 

Fowmy_0-1621670686061.png

Paste the below code on a new blank query in the Advanced Editor and see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLSNTDVNTJU0lEyNFCK1aGiiDFcxIjKIiZwEWOyRWIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Int64.Type}},"en-gb"),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Count", each _, type table [Date=nullable date, Value=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1) ),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Date", "Value", "Index"}, {"Date", "Value", "Index"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded Custom", "Custom", each if [Index] = 1 then "Original" else "Duplicate"),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Index"})
in
    #"Removed Columns"

 

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
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.