Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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 
 
1 ACCEPTED SOLUTION

Good morning @Anonymous 

I can, yes.

FreightForecast.jpg

Updated PBIX file available here:  https://www.dropbox.com/s/eu9rx5206hqpddo/FreightForcast.pbix?dl=0

 

View solution in original post

16 REPLIES 16
MFelix
Super User
Super User

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


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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 

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


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi @MFelix 

 

Thank you for reply. Below is my table;

 

  • [freightcost] is captured from database
  • [FreightCost LY] = (with editing by your kind response) FreightCost LY = SUMX ( Dateforec; CALCULATE ( SUM ( transportorder[freightcost] ); DATEADD ( dateforec[Date (bins)]; -12; MONTH ) ) )
  • [FreightCost Forecast] = if(sum(transportorder[freightcost])=0;calculate(transportorder[FreightCost LY]*0.8);"")
  • [Adjusted FreightCost Forecast] = max(sum(transportorder[freightcost]);transportorder[FreightCost LY]*0.8)
 
Purpose is that [FreightCost Forecast] should be calculated as .8 times last year's freight cost, IF freightcost is missing. 
 
Henrik

 

1111.png

I believe the problem is that the missing freight cost is not = 0, it is blank.  Try this.

[FreightCost Forecast] =
IF (
    ISBLANK ( SUM ( transportorder[freightcost] ) );
    [FreightCost LY] * 0,8;
    BLANK ()
)

 

Anonymous
Not applicable

Hi @jdbuchanan71

I tried your suggestion, but unfortunately no change.

Henrik

Hello @Anonymous Could you share a sample of your model?

Can you also share a data sample? Need to know what columns you have and the values. No need for actual data just a sample.

Regards,
MFelix

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi @MFelix,

What kind of data do you need? freightcharge is double. Date is date (calendar created in Power BI and linked to Pickupdate in dataset). Date (bins) is Date grouped by months.

I still think that the problem is that Power BI for some reason converts the measure to variant. If I could use other logic to produce the same result or convert it to a summarized measure it would probably solve it.

Henrik

Hello @Anonymous 

I put together what I think you are looking for.

From the linked sample fileFrom the linked sample file

You can download my sample file here and take a look at the measures:

https://www.dropbox.com/s/eu9rx5206hqpddo/FreightForcast.pbix?dl=0

 

@@jdbuchanan71  - I need help with the same issue, but im not able to download the pbix file.

 

Is it possible to share the measure used for FreightCostLY or FreightCostForecast ?

Sure, here you go.

FreightCostLY = 
CALCULATE(
    [FreightCost],
    SAMEPERIODLASTYEAR(Dates[Date])
)
FreightCostForcast = 
VAR FutureMonths = FILTER ( VALUES ( Dates[Date (bins)] ) , [FreightCost] = 0 )
RETURN 
SUMX(
    FutureMonths,
    [FreightCostLY] * .8
)

 

Thanks a lot

Anonymous
Not applicable

Hi @jdbuchanan71 

 

Yes, looks very much like my table. Can you get the column FreightCostFroecast to sum total?

 

Thanks,

Henrik

Good morning @Anonymous 

I can, yes.

FreightForecast.jpg

Updated PBIX file available here:  https://www.dropbox.com/s/eu9rx5206hqpddo/FreightForcast.pbix?dl=0

 

Anonymous
Not applicable

@jdbuchanan71 

 

Thank you very much! Excellent solution. 

 

Best regards,

Henrik 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.