Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Sum by grouped fields

Hello guys,

 

I have two tables (Model and Ocurrencies) and I wish to create two measures which sum the mileages of models by the unit field.  In addition, these two tables have a relationship. However, on the Ocurrencies table, the registers must be grouped by the model and month so that distinct registers are considered. Below are my data:

 

Model table:

ModelMileageUnit
Area 117000KM2
Area 2265,1KM
Area 356,09KM

 

Ocurrencies table:

ModelMonth
Area 1January
Area 1January
Area 1January
Area 1February
Area 2January
Area 2January
Area 3March
Area 3March
Area 3April

 

Result when unit equal "KM2":  
ModelMonthMileage
Area 1January17000
Area 1February17000

 

Result of the sum measure when unit equal "KM2"
34000

 

Result when unit equal "KM":  
ModelMonthMileage
Area 2January265,1
Area 3March56,09
Area 3April56,09

 

Result of the sum measure when unit equal "KM"
377,28

 

Thank you so much for your help!!

 

Best wishes,

Gustavo Xerez

  • Hi, Anonymous ;

    You could create a measure as follows:

    Measure = 
    IF(ISINSCOPE('Model'[Model]), 
      CALCULATE( SUM('Model'[Mileage]),FILTER('Ocurrencies',[Month]=MAX('Ocurrencies'[Month]))),
      SUMX(SUMMARIZE('Ocurrencies',[Model],[Month],"1",SUM('Model'[Mileage])),[1]))

    The final output is shown below:


    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

  • Anonymous , One to many join between Model  and Ocurrencies

     

    Then a measure like 

     

    Sumx(Ocurrencies, related(Model[Mileage])

    • Anonymous's avatar
      Anonymous
      Not applicable

      amitchandak, I have created a measure as you described and unfortunately, it didn´t work. I put the measure in a card and the sum return 68.698,47 using the same data of the post.

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, Anonymous ;

    You could create a measure as follows:

    Measure = 
    IF(ISINSCOPE('Model'[Model]), 
      CALCULATE( SUM('Model'[Mileage]),FILTER('Ocurrencies',[Month]=MAX('Ocurrencies'[Month]))),
      SUMX(SUMMARIZE('Ocurrencies',[Model],[Month],"1",SUM('Model'[Mileage])),[1]))

    The final output is shown below:


    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.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi v-yalanwu-msft,

       

      Thanks a lot for your help !! I wish to know how to create these two measures as you have done so that one returns the sum when the unit is "KM" and the other one when the unit is "KM2". Both of them will not need a selection of KM or KM2.

       

      Thanks in advance.

       

      Best regards,

      Gustavo Xerez