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
sph1nkz
Frequent Visitor

Do not include blank values in the results of calculated columns

Hi,

 

I create calculated column to compute distance between 2 locations.

 

End state would be:

 

1. Compute results excluding the location itself

2. Do not put any value on results if either of the value of latitude & longitude is blank.

 

Here is my code credits to @AIB:

 

Distance (KM) =
VAR Lat1 = facilities_tbl[Latitude]
VAR Lng1 = facilities_tbl[Longitude]
VAR name_ = facilities_tbl[Name of plant]
VAR P =
DIVIDE ( PI (), 180 )
RETURN
MINX (
FILTER ( facilities_tbl, facilities_tbl[Name of plant] <> name_ ),
VAR Lat2 = facilities_tbl[Latitude]
VAR Lng2 = facilities_tbl[Longitude]
VAR A =
0.5
- COS ( ( Lat2 - Lat1 ) * P ) / 2
+ COS ( Lat1 * P )
* COS ( lat2 * P )
* (
1
- COS ( ( Lng2 - Lng1 ) * P )
) / 2
VAR final =
12742 * ASIN ( ( SQRT ( A ) ) )
RETURN
final
)

 

Here's the result:

 

sph1nkz_0-1665203158670.png

 

Should not include the 0s in the results if either of the latitude or longitude is blank.

 

Thanks 

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Change the RETURN expression to:

...
RETURN
IF (
    OR (
        ISBLANK ( facilities_tbl[Latitude] ),
        ISBLANK ( facilities_tbl[Longitude] )
    ),
    BLANK (),
    final
)








Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

2 REPLIES 2
PaulDBrown
Community Champion
Community Champion

Change the RETURN expression to:

...
RETURN
IF (
    OR (
        ISBLANK ( facilities_tbl[Latitude] ),
        ISBLANK ( facilities_tbl[Longitude] )
    ),
    BLANK (),
    final
)








Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






It worked!!! Thank you so much @PaulDBrown. Really appreciate your help.

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.