Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Calculated measure that won't sum

Hi,

 

I have a question about a calculated measure that won't sum in a table. 

 

The measure is 

 

FreightCost Forecast = if(sum(transportorder[freightcost])=0;calculate(transportorder[FreightCost LY]*0,8);blank())
 
[freightcost] is captured from database (data type is double)
[FreightCost LY] = calculate (sum(transportorder[freightcost]); dateadd (dateforec[date]; -12; MONTH))
 
I have created a table of the measures
- Each row and sum of column of [FreightCost LY] are correct and works fine. 
- [FreightCost Forecast] shows correct values on each row, but doesn't show sum of column in the table (it doesn't sum individual rows and leaves total empty). 
 
Data type of [FreightCost Forecast] is Decimal Number according to Power Bi. 
 
I have tried various alternatives, e.g.  if(sum(transportorder[freightcost])=0;calculate(transportorder[FreightCost LY]*0,8);0) without success. 
 
Any ideas or instructions to what I'm doing wrong?
 
Thanks!
Henrik 
 

16 Replies

  • Hi Anonymous ,

     

    Measures in DAX are calculated based on context so the columns, slicers, filters visuals interactions can change the calculation of a measure.

     

    In your case since the total row doesn't have dateforec[date] associated with it, because it's an aggregation line the result is blank.

     

    You need to redo your measure to have an aggregator for making the sum of the rows. Something similar to:

     

    [FreightCost LY] =
    SUMX (
        Dateforec;
        CALCULATE (
            SUM ( transportorder[freightcost] );
            DATEADD ( dateforec[date]; -12; MONTH )
        )
    )

    Be aware that this can change your final result also, without any sample data is difficult to give you a better answer.

     

    If this measure doesn't work please share a sample of your model.

     

    Regards,

    MFelix

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi,

       

      Thank you for your reply, but this didn't solve the problem. My measure [Freightcost Forecast] still doesn't show a column total although I applied the changes to [FreightCost LY] as proposed. Actually, it didn't change the outcome of [FreightCost LY] either. What I want is that I only want [FreightCost Forecast] to show a value only in case [freightcost] is null (as for future dates), which works fine with the if statement in the measure formula. I think that the problem is that the measure gets caulcated as variant and data type variants don't sum in tables. I have tried to use value([Freight Cost Forecast]), but no change. 

       

      Henrik

       


      MFelix wrote:

      Hi Anonymous ,

       

      Measures in DAX are calculated based on context so the columns, slicers, filters visuals interactions can change the calculation of a measure.

       

      In your case since the total row doesn't have dateforec[date] associated with it, because it's an aggregation line the result is blank.

       

      You need to redo your measure to have an aggregator for making the sum of the rows. Something similar to:

       

      [FreightCost LY] =
      SUMX (
          Dateforec;
          CALCULATE (
              SUM ( transportorder[freightcost] );
              DATEADD ( dateforec[date]; -12; MONTH )
          )
      )

      Be aware that this can change your final result also, without any sample data is difficult to give you a better answer.

       

      If this measure doesn't work please share a sample of your model.

       

      Regards,

      MFelix


       

      Henrik 

      • MFelix's avatar
        MFelix
        Icon for Super User rankSuper User

        Hi Anonymous ,

         

        As I refer measures and calculations are based in context so the way you setup the tables and the measure will alter the final result.

         

        Can you share a sample model or a mockup with expected result so I can check what has to be changed?

         

        Regards,

        MFelix