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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
SevsBo
Helper III
Helper III

Calculated table to get earliest highest value?

I am trying to find the earliest occurances of the highest value in a given column. 

 

Here is the initial state of the data:

 

ItemCostDate
a1101/01/2022
a1301/05/2022
a1101/06/2022
a1201/03/2023
a1101/07/2023
b2201/03/2021
b2301/02/2022
b2101/04/2022
b2101/07/2022
b2301/09/2022
b2101/11/2022

 

As we can see Item a1 had it's higest cost on 01/05/2022.

Item b2 had two instances of highest cost, one in 01/02/2022, and the other on 01/09/2022. I want to capture only the first one.

So from this data I want to get the following result:

 

ItemCostDate
a1301/05/2022
b2301/02/2022

 

I have so far used a query level action, first sorting Date Ascending, then sorting Cost Descending before deduping the whole thing, as that's a logic that works in Excel. I also used buffer.table when sorting to ensure all data is captured in both sorts.

 

But I also want to verify this data, so I am looking at making a calcualted column against the original version of this table.

 

Can anyone help with how that should look like?

 

4 REPLIES 4
SevsBo
Helper III
Helper III

As an update, I tried deduping based on the columns that were causing me issues, but it didn't help.

 

Still getting the above error. Any ideas?

create a temporary table like

Tmp table =
ADDCOLUMNS (
    SUMMARIZE ( 'Table', 'Table'[Item], 'Table'[Date] ),
    "@num rows", CALCULATE ( COUNTROWS ( 'Table' ) )
)

that should help you identify any remaining duplicates.

johnt75
Super User
Super User

You can create a calculated table like

My Table =
INDEX(
	1,
	'Table',
	ORDERBY( 'Table'[Cost], DESC, 'Table'[Date], ASC),
	PARTITIONBY( 'Table'[Item]),
	MATCHBY( 'Table'[Item], 'Table'[Date])
)

Just for reference, it needed a Blank argument as well, I chose "Default".

 

I am getting an error though:

 

Despite of MatchBy columns being specified, duplicated rows are encountered in INDEX's Relation parameter. This is not allowed. The current operation was cancelled because another operation in the transaction failed.

 

I think this might be because some Items might have the same date and rating twice, will try to dedupe that part on query level and then run this again.

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.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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