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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
greenawayr
Helper I
Helper I

Evaluate duplicate IDs on another column

Hi, 

 

Hope this makes sense, but if it does, appreciate any help.

 

I have a table where I need to evaluate each set of duplicated ID's and output in a new column if that set meets a condtion.

 

Example

 

IDDateOutput
117/10/2021      0
118/10/2021      0
116/10/2019      0
217/10/2021      1
210/10/2021      1

 

So the above shows my output column for ID 1 = 0 because all three rows for "1" have been evaluated and we found that 1 of the dates was in the past (it only needs 1 date to have "expired" for the output to be 0). ID 2 = 1 because the dates are all in the future.

 

Any idea how I can create a column like "Output" for this?

 

Hope I've  explained this well enough.

 

Thanks

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@greenawayr 

you can also try this

Column = if(CALCULATE(min('Sheet2'[Date]),ALLEXCEPT(Sheet2,Sheet2[ID]))<today(),0,1)

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
ryan_mayu
Super User
Super User

@greenawayr 

you can also try this

Column = if(CALCULATE(min('Sheet2'[Date]),ALLEXCEPT(Sheet2,Sheet2[ID]))<today(),0,1)

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you both for these suggestions. These both fulfil my requirements.

 

One thing I omitted though was that I need to do a count of the unique items. I was assuming I'd get answers back in M rather than DAX, and that would allow me to just remove the duplicates.

 

However, I can still do this with a separate measure in DAX so thanks.

 

I actually came up with a convaluted way to do it in Power Query without the use of M. Not an efficient way, so I will be replacing it with your suggestions, but I thought I'd add it ere for anyone who's scared of code.

 

I created a copy of the Query, and then used the Group By function, setting my "aggregate" column as a Min of the Date column. This meant the single row left by the Group By function gave me the lowest date in the collection. I then created a very basic custom column with an IF that checked whether this date was in the past or future. In the past = 0, future = 1.

 

I then used the Merge Query to merge my new query with the original based on the ID, extracting the Output column from the new table and that gave me my solution. I imagine this is a resource hungry way of doing it, but it's another solution also.

 

If someone can deliver a similar resource using M code that would be the perfect answer for me.

 

Thanks

amitchandak
Super User
Super User

@greenawayr , create a new column like

if(isblank(countx(filter(table, [ID] = earlier([ID]) && [Date] <today()),[Date])),1,0)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.