Forum Discussion

AlessandroFossi's avatar
AlessandroFossi
New Member
2 years ago
Solved

Euclidean Distance measure with DAX

Dear Community, 

 

I found myself stuck with this formula in DAX, seems ok because the editor does not throws an error but the measure is always zero in power BI charts. 

The measure is intended to calculate euclidean distance between two multi-variable time-series that you find in this table exemple:

 

FechaAnoDiaMesppOriginal Without SuffixSuffixDatetimehours
1/1/2018 1:002018110.2932URAN_AggrPROP1/1/2018 1:001:00
1/1/2018 1:002018110.0147Net_importsPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110.0016NGAS_CCGT_new_AggrPROP1/1/2018 1:001:00
1/1/2018 1:002018110.0003SUN__PV____GenericPROP1/1/2018 1:001:00
1/1/2018 1:002018110.0003SUN__PV____GenericPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110SUN__CSP___GenericPROP1/1/2018 1:001:00
1/1/2018 1:002018110.5017WIND_ONSHO_GenericPROP1/1/2018 1:001:00
1/1/2018 1:002018110.0447WATR_ROR___AggrPROP1/1/2018 1:001:00
1/1/2018 1:002018110.0147WATR_STO___AggrPROP1/1/2018 1:001:00
1/1/2018 1:002018110.102NRES_AggrPROP1/1/2018 1:001:00
1/1/2018 1:002018110.0148BIOM_AggrPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110.0157WAST_AggrPROP1/1/2018 1:001:00
1/1/2018 1:002018110.0155BIOM_AggrPROP1/1/2018 1:001:00
1/1/2018 1:002018110WATR_PSP___AggrPROP1/1/2018 1:001:00
1/1/2018 1:002018110.0971NRES_AggrPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110.0101COAL_AggrPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110.0149WAST_AggrPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110.0421WATR_STO___AggrPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110.0106COAL_AggrPROP1/1/2018 1:001:00
1/1/2018 1:002018110.2856URAN_AggrPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110Net_importsPROP1/1/2018 1:001:00
1/1/2018 1:002018110.4778WIND_ONSHO_GenericPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110.0425WATR_ROR___AggrPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110NGAS_CCGT_new_AggrPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110WATR_PSP___AggrPROP_OBS1/1/2018 1:001:00
1/1/2018 1:002018110.0001SUN__CSP___GenericPROP_OBS1/1/2018 1:001:00

 

 

and the DAX measure is this: 

 

EuclideanDistance =
VAR SelectedSuffix = "PROP"  -- Replace with the desired suffix ("PROP" or "OBS")
VAR Series1Values =
    ADDCOLUMNS(
        SUMMARIZE(
            FILTER('df (2)', 'df (2)'[Suffix] = SelectedSuffix),
            'df (2)'[Datetime],
            'df (2)'[Original Without Suffix]
        ),
        "pp_Series1", CALCULATE(MAX('df (2)'[pp]))
    )
VAR Series2Values =
    ADDCOLUMNS(
        SUMMARIZE(
            FILTER('df (2)', 'df (2)'[Suffix] <> SelectedSuffix),
            'df (2)'[Datetime],
            'df (2)'[Original Without Suffix]
        ),
        "pp_Series2", CALCULATE(MAX('df (2)'[pp]))
    )
VAR IntersectedValues =
    NATURALINNERJOIN(Series1Values, Series2Values)

VAR SumOfSquares =
    SUMX(
        IntersectedValues,
        POWER([pp_Series1] - [pp_Series2], 2)
    )
VAR EuclideanDistance =
    SQRT(SumOfSquares)
RETURN
    EuclideanDistance
 
 
Any idea on how to solve this?
 
Thanks in advance
 
Alessandro
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi AlessandroFossi ,

    I looked at your DAX code and copied your values into Power BI and found the problem to be the following.

    For this part of the image below, he needs to recreate two new tables.

    You are using the NATURALINNERJOIN function, the join function 'NATURALINNERJOIN' requires at-least one common join column. So I think you can modify your code a bit.

     

     

     

    Best Regards

    Yilong Zhou

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi AlessandroFossi ,

    I looked at your DAX code and copied your values into Power BI and found the problem to be the following.

    For this part of the image below, he needs to recreate two new tables.

    You are using the NATURALINNERJOIN function, the join function 'NATURALINNERJOIN' requires at-least one common join column. So I think you can modify your code a bit.

     

     

     

    Best Regards

    Yilong Zhou

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.