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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
rush
Helper V
Helper V

Remove duplicate values in a column based on Month and year with DAX

Hi All

 

I have done a lookup to bring values in from another table which I have done so but it is displaying multiple values as there are multiple entries per month-year for a staff member

I am trying to remove duplicates or filter the lookup dax code to only bring one value per month-year.

My lookup dax code below:

 

 

Est. Monthly Cost = 

CALCULATE( 
    FIRSTNONBLANK(Billing_Summary[Est. Monthly Cost],TRUE()), 
    FILTER(Billing_Summary,Billing_Summary[StaffID_DateInt] = Billing_Hours_Detail[StaffID_DateInt] ) )

 

 

 



rush_0-1626863168026.png

File - Example 

1 ACCEPTED SOLUTION

Hi @rush ,

 

1.Use group by

1.png2.png

4.png

 

2.Add a custom column

3.png

 

3.Expand the column

5.png

 

4.Add a conditional column

6.png

 

5.The result

7.png

 

Best Regards,

Stephen Tao

 

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

7 REPLIES 7
v-stephen-msft
Community Support
Community Support

Hi @rush ,

 

You can try to create an index column.

18.png

 

Then use the following measure

Measure = IF(MAX('Table1'[Index])=1,[Est. Monthly Cost])

 

Calculated columns can also be created as follows

Column = IF([Index]=1,[Est. Monthly Cost])

 

Example:

19.png

20.png

 

Best Regards,

Stephen Tao

 

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

 

 

 

 

@v-stephen-msft Unfortunately that did not work as I have numerous records for different staff for every month.

I think it would work if I can filter my calculated column to bring me the MAX value of Est. Monthly once for each month-year.

Please see DAX calculated column where I am trying to only bring one value per Staff per Month-Year but it is not working.

Max Monthly Cost per StaffID per Month-Year = 

CALCULATE( MAX(Billing_Hours_Detail[Est. Monthly Cost]) , KEEPFILTERS(Billing_Hours_Detail[Date_Int_YYYYMM01] ) , KEEPFILTERS(Billing_Hours_Detail[StaffID] ))




Hi @rush ,

 

You could refer to this article to get a ranking group by staff name column.

Here's a simple example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VdAxDsIwDAXQq6DMrRQ7seJ4Y2JFrFUHVLKhAqLcn7QkxVksD0/+Xx4GA4BoOnNJr096L3kD21vXIxwAxFozdrs5TlN6LulWkN8QCpBG5/t1nn8Gq3GCsBki5iYMqYaxgNNGhbm9kZecsaIYQ2gO+ZIVBRqhznCtEwRYm3/lWAmJs5qcHnnkrlS6ro8Zvw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Phase = _t, #"Date start" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Phase", type text}, {"Date start", type text}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Date start", type datetime}}, "en-GB"),
    #"Grouped Rows" = Table.Group(#"Changed Type with Locale", {"Code"}, {{"Column", each _, type table [Code=nullable number, Phase=nullable text, Date start=nullable datetime]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Rank", each Table.AddIndexColumn([Column],"rank",1,1)),
    #"Expanded Rank" = Table.ExpandTableColumn(#"Added Custom", "Rank", {"Date start", "Phase", "rank"}, {"Rank.Date start", "Rank.Phase", "Rank.rank"})
in
    #"Expanded Rank"

8.png

 

Best Regards,

Stephen Tao

 

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

Best Regards,

Stephen Tao

 

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

@v-stephen-msft Thank you but this is not what I require.

I need to bring back one value per Staff per Month-Year.

Hi @rush ,

 

Can you give all your sample data? From your dax, I guess you have two tables. Without sample data, it is difficult to meet your requirements by language description alone.

 

Best Regards,

Stephen Tao

 

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

Hi @v-stephen-msft 

It is just one table containing multiple rows per year-month for different staff.

I am just trying to bring back one value from the Est. Monthly Cost column per staff per month-year. 


I have updated the link to a new excel file that contains sample data. The last column is what I am trying to achieve.

Hi @rush ,

 

1.Use group by

1.png2.png

4.png

 

2.Add a custom column

3.png

 

3.Expand the column

5.png

 

4.Add a conditional column

6.png

 

5.The result

7.png

 

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.