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
nhmpp
Helper I
Helper I

Distance from Location based on overlapping times

I have data about lots of differnet locations, and then separate info on events going on in the area. I have a formula set up for distance between the event and the different locations, and the table looks like this, where you filter by one location at a time.

 

nhmpp_0-1667583357786.png

 

 

Next, I have a table that shows mutliple locations at a time, and differnet revenue that they earned per day. Those calculations are not important. When there is an event from the events table that overalps with that certain date, the name of it appears in the "PredictHq Event" column, filtered by highest "local rank" which is how popular an event is. There are usually multiple events per day, so this is the reason for that. What I need in the final column is the KM from that event that gets pulled, to the specific location of that row. Right now, it is calulcating as shown, even though the first table is calculating correctly. I think it may be an issue of not working right with the event name. 

nhmpp_3-1667583675666.png

 

Here are my formulas right now:

 

PredictHq Event 1=
MAXX (
    TOPN (
        1,
        FILTER (
            PredictEvents,
                PredictEvents[Event_End] > MAX(LocationRevenues[starts_at_in_time_zone])
                && PredictEvents[Event_Start] <= MAX(LocationRevenues[starts_at_in_time_zone])
        ),
        PredictEvents[Loc_Rank],DESC
    ),
    PredictEvents[Event_Name]
)

 

 

Km from Event for Table 2=

MAXX( TOPN (
        1,
        FILTER (
            PredictEvents, PredictEvents[Event_Name] = LocationRevenues[PredictHqEvent1]
                && PredictEvents[Event_End - Copy] > MAX(LocationRevenues[starts_at_in_time_zone - Copy])
                && PredictEvents[Event_Start - Copy] <= MAX(LocationRevenues[starts_at_in_time_zone - Copy])
        ),
        PredictEvents[Loc_Rank],ASC
    ) , [KmFromLocation]
)
 
 
KmFromLocation = 
var Lat1 = MIN(Locations[latitude])

var Lon1 = MIN(Locations[longitude])

var Lat2 = MIN(PredictEvents[Lat])


var Lon2 = MIN(PredictEvents[Lon])

var P = DIVIDE( PI(), 180 )

var A = 0.5 - COS((Lat2-Lat1) * p)/2 +

COS(Lat1 * p) * COS(lat2 * P) * (1-COS((Lon2- Lon1) * p))/2

var final = 12742 * ASIN((SQRT(A)))

return final
 
 
I appreciate any help! I am not able to share the powerbi file. 
1 REPLY 1
v-yanjiang-msft
Community Support
Community Support

Hi @nhmpp ,

According to your discription "the KM from that event that gets pulled, to the specific location of that row", what "specific location" means?

 

Best Regards,
Community Support Team _ kalyj

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.