Forum Discussion

mikebravo's avatar
mikebravo
Regular Visitor
7 years ago

Do I need variables?

Hello folks,

 

   New BI user here but not new to analysis.  I'm trying to transition myself into BI and out of Excel as I have reached the limits if Excel with the work that I do but I am hampered by the varrying syntax between the two.  I exclusively used dynamic tables in Excel so referencing tables and columns is no problem for me.  

 

So my problem:

    I'm trying to find the sum of one column based on a row value and divide that with sum of another column based on that same row value.  In Excel, I would typically just use  =SUMIFS(xxxxx)/SUMIFS(xxxxx)  The overall lfunction will be more indepth and complex than that because I will build in dates and trends over dates into it at some point but I need to start with the basics.

 

Here is where I am stuck:

     

Trend = DIVIDE(CALCULATE(SUMX(FILTER(Omnitrack_PerformanceMetrics,Omnitrack_PerformanceMetrics[EquipmentID]=Omnitrack_PerformanceMetrics[EquipmentID]),Omnitrack_PerformanceMetrics[Dist])),CALCULATE(SUMX(FILTER(Omnitrack_PerformanceMetrics,Omnitrack_PerformanceMetrics[EquipmentID]=Omnitrack_PerformanceMetrics[EquipmentID]),Omnitrack_PerformanceMetrics[Totalfuel])),0)
 
If I strip away the DIVIDE function, as well as one of the other SUMX's, I get the correct values.  So I know the CALCULATE(SUMX functions are working.  I just can't seem to get it to divide the two and come up with the correct value.
 
Any help is greatly appreciated!

5 Replies

  • Why are you using SUMX() for this particular exercise instead of just a simple CALCULATE() with a SUM() inside? The filtering you do doesn't seem to require that the formula is evaulated at row context.

    • mikebravo's avatar
      mikebravo
      Regular Visitor

      Ignorance possibly..?? ;)    In earlier trials, I was using CALCULATE and SUM with FILTER and EARLIER.  This is a simplified version as there will be 3 criteria for each function so I thought maybe I shoudl use SUMX.  

      • adambhappy's avatar
        adambhappy
        Resolver II

        The context transition is one of the hardest things to get your head around in terms of DAX, it takes a while so not surprising.

         

        Can you share a print screen of your tables and maybe a small sample set of the data?

         

        Can I assume that [Dist] and [Totalfuel] refers to measures and not columns?