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
murphm6
Helper II
Helper II

Compare values across multiple rows with same ID to create flags

Hi everyone,

 

I'm running into a problem where I need to compare multiple rows in a table to see if a certain charge type is higher than another. 

 

Here is what the data looks like: Essentially, I want to look at each 'Short Invoice' and create a flag (simple 1,0) if there is a 'Cost' that is higher than the 'Ocean Freight' cost. How can I compare across multiple rows where they all have a unique ID?

murphm6_0-1663948663441.png

 

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

Try the adding the following column to your table. (Replace costTable with your table name.)

 

Grtr Ocean =
var _freightValue =
// find Ocean Freight value for given short invoice
CALCULATE(
    MAX(costTable[Cost]),
    ALLEXCEPT(costTable,costTable[Short Invoice]),
    costTable[Charge Type] = "Ocean Freight"
)
var _result =
// test if cost is greater than Ocean Freight value for given short invoice
IF(
    [Cost] > _freightValue && costTable[Charge Type] <> "Ocean Freight",
    1,
    0
)
Return
_result



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

Proud to be a Super User!





View solution in original post

4 REPLIES 4
jgeddes
Super User
Super User

Try the adding the following column to your table. (Replace costTable with your table name.)

 

Grtr Ocean =
var _freightValue =
// find Ocean Freight value for given short invoice
CALCULATE(
    MAX(costTable[Cost]),
    ALLEXCEPT(costTable,costTable[Short Invoice]),
    costTable[Charge Type] = "Ocean Freight"
)
var _result =
// test if cost is greater than Ocean Freight value for given short invoice
IF(
    [Cost] > _freightValue && costTable[Charge Type] <> "Ocean Freight",
    1,
    0
)
Return
_result



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

Proud to be a Super User!





This seems to be on the right track. However I just ran it and when filtering for values that have '1', some of the returned 'Short invoices' don't have any ocean freight costs. Is there a way to exclude short invoices that don't have any associated 'OCean freight' charge types?

Amend the IF test line to

[Cost] > _freightValue && costTable[Charge Type] <> "Ocean Freight" && NOT(ISBLANK(_freightValue))



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

Proud to be a Super User!





That worked, thanks!!

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.