Forum Discussion

jonoren's avatar
jonoren
Frequent Visitor
4 years ago
Solved

Many to Many relationship Standard Deviation Calculation

For the example, I have 2 simple tables: 

1. Countries Table:

CountryID  Name                CurrencyCode
1United StatesUSD
2United KingdomGBP
3CanadaCAD
4GermanyEUR
5FranceEUR

 

2. CurrencyExchangeRates Table:

CountryDateCurrencyCodeValue
1;1/1/2022USD1
1;1/2/2022USD1
1;1/3/2022USD1
2;1/1/2022GBP1.2
2;1/2/2022GBP1.3
2;1/3/2022GBP1.35
3;1/1/2022CAD0.7
3;1/2/2022CAD0.6
3;1/3/2022CAD0.8
4;1/1/2022EUR1.02
4;1/2/2022EUR1.1
4;1/3/2022EUR0.9
5;1/1/2022EUR1.02
5;1/2/2022EUR1.1
5;1/3/2022EUR0.9

 

And I'm trying to somehow end up with the following countries table:

 

CountryIDNameCurrencyCodeStandard Deviation
1United StatesUSD0
2United KingdomGBP0.076376262
3CanadaCAD0.1
4GermanyEUR

0.100664459

5FranceEUR

0.100664459

 

I would prefer if the solution would be implemented using Power BI, and if through Power Query then avoiding M code unless it's inevitable. 

 

Thanks a lot!

 

Jonathan

  • Hi, jonoren ;

    The relationship as follow:

    Then create a measure.

     

    Measure = STDEVX.S(SUMMARIZE('ExchangeRate',[CountryDate],[CurrencyCode],'ExchangeRate'[Value]),[Value])

     

    The final show:


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Dhacd's avatar
    Dhacd
    Resolver III

    Hi jonoren  Can you confirm whether the records in the country table are distinct or not?
    Regards,
    Atma.

    • jonoren's avatar
      jonoren
      Frequent Visitor

      I just edited the question to reflect they are not distinct

      • Dhacd's avatar
        Dhacd
        Resolver III

        Hi jonoren  Please check whether you are using the countryside from the country table and the country from the exchange table are used to create a relation.

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

        Thanks and Regards,
        Atma.

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Community Support

    Hi, jonoren ;

    The relationship as follow:

    Then create a measure.

     

    Measure = STDEVX.S(SUMMARIZE('ExchangeRate',[CountryDate],[CurrencyCode],'ExchangeRate'[Value]),[Value])

     

    The final show:


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.