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
ericOnline
Post Patron
Post Patron

Using MEDIAN as LOOKUP column?

Hello,

I want to LookUp records based on the record closest to the Median value of a column. 

Example:

 

 

MAP_ZOOM_LAT = 

VAR varMid = MEDIAN(table[column1])
RETURN

    LOOKUPVALUE(
        table[latitude], 
        varMid,
        BLANK()
    )

 

 

 The error I receive is:

"Function LOOKUPVALUE expects a column reference as argument number 2"

ericOnline_0-1600364016127.png

 

How do I determine which record is closest to the Median value in a given column?

Thank you

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@ericOnline Maybe this:

MAP_ZOOM_LAT = 
  VAR __varMid = MEDIAN(table[column1])
  VAR __Table = 
    ADDCOLUMNS(
      'table',
      "diff",ABS([latitude]-__varMid)
    )
  VAR __Min = MINX(__Table,[diff])
  VAR __Result = MINX(FILTER(__Table,[diff]=__Min),[ID])
RETURN
  [ID]

That's the general idea, basically a Lookup Min/Max - https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434

 

Not 100% of what you are trying to return/show so I just made up an "ID" column. You could use a variation of this as a flag variable that you could use as a Complex Selector - https://community.powerbi.com/t5/Quick-Measures-Gallery/The-Complex-Selector/m-p/1116633#M534

MAP_ZOOM_LAT = 
  VAR __CurrentLat = MAX(table[latitude])
  VAR __varMid = MEDIAN(table[column1])
  VAR __Table = 
    ADDCOLUMNS(
      'table',
      "diff",ABS([latitude]-__varMid)
    )
  VAR __Min = MINX(__Table,[diff])
  VAR __Result = IF(__CurrentLat = __Min, 1, 0)
RETURN
  __Result

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
v-jayw-msft
Community Support
Community Support

Hi @ericOnline ,

 

Has the problem be solved? 

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Greg_Deckler
Super User
Super User

@ericOnline Maybe this:

MAP_ZOOM_LAT = 
  VAR __varMid = MEDIAN(table[column1])
  VAR __Table = 
    ADDCOLUMNS(
      'table',
      "diff",ABS([latitude]-__varMid)
    )
  VAR __Min = MINX(__Table,[diff])
  VAR __Result = MINX(FILTER(__Table,[diff]=__Min),[ID])
RETURN
  [ID]

That's the general idea, basically a Lookup Min/Max - https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434

 

Not 100% of what you are trying to return/show so I just made up an "ID" column. You could use a variation of this as a flag variable that you could use as a Complex Selector - https://community.powerbi.com/t5/Quick-Measures-Gallery/The-Complex-Selector/m-p/1116633#M534

MAP_ZOOM_LAT = 
  VAR __CurrentLat = MAX(table[latitude])
  VAR __varMid = MEDIAN(table[column1])
  VAR __Table = 
    ADDCOLUMNS(
      'table',
      "diff",ABS([latitude]-__varMid)
    )
  VAR __Min = MINX(__Table,[diff])
  VAR __Result = IF(__CurrentLat = __Min, 1, 0)
RETURN
  __Result

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.