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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Mojtaba
Frequent Visitor

Calculate a function as long as you have value for a certain variable

I have a below function

Potential Saving calculation = ([Expected Usage]-[Actual Usage])*AVERAGE(Forecast_Table[Price])
 
If there is no value for Actual Usage the whole formula produses wrong result
I just want to tell power bi: calculate this as long as you have value for Actual Usage.
I have same problem here as well
Forecast Accuracy = ABS(ABS((SUM(Actual_Table[Expected_Usage])-[Actual Usage])) / [Actual Usage]*100 -100)
 
I just want to tell power bi: calculate forcast accuracy as long as or up until you have value for Actual Usage.
11 REPLIES 11
Anonymous
Not applicable

Hi @Mojtaba ,

 

Try adding "+0" after [Actual Usage].

Potential Saving calculation = ([Expected Usage]-([Actual Usage]+0))*AVERAGE(Forecast_Table[Price])

 

Best Regards,

Jay

Mojtaba
Frequent Visitor

I tried but no changes happened

I just copy pasted your code please see below  screen shot

still takes in account expected usage when there is no actual usage

instead of showing only 95k it shows 981K

 

 

potential saving.png

Hi @Mojtaba 

 

I am really sorry but without more detailed information and the model, I won't be able to assist.  If you are able to share, I am sure that a resolution can be created. It is just a bit difficult making assumptions, etc., on the data types, relationships, filters, etc., that are not transparent through the screenshots, etc.

 

I trust you understand.


Theo

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Mojtaba
Frequent Visitor

Could it be because this is how I calculated actual usage?

Actual Usage = SUMX(DISTINCT(Actual_Table[Month]), FIRSTNONBLANK(Actual_Table[Actual_Usage], 0))

@Mojtaba I'm unsure what your Actual Usage measure in the current state is aiming to achieve but if you are just wanting to SUM the value of your [Actual_Usage] column, I would highly recommend just using SUM. For example:

 

TotalActualUsage = SUM ( 'Actual_Table'[Actual Usage]).  

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Mojtaba
Frequent Visitor

I did this to sum only unique value for each month.For some reason ,not sure why.I had repetitive number in a month

@Mojtaba The reason that this may have occurred is because of the format that your date columns (i.e. Month Year) are currently structured.  It is likely they were sitting as "text" and not connected reflective of a "date".  I believe it would be of material benefor for you to add a Data table that acts as the "source of truth" when you're using dates to slice and filter your data.  I highly recommend you add a Date table and use that as the basis of filtering, axis, etc for your report. You can get this from here: https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/).

 

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Mojtaba
Frequent Visitor

what info you need?

snap shots of table relationships?

and field parts?

@Mojtaba yes please. An example of data used, a snapshot of your relationships, etc. Thank you.

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Mojtaba
Frequent Visitor

relaationshiprelaationshiptable 1table 1table 2table 2fieldsfields

TheoC
Super User
Super User

Hi @Mojtaba 

 

For the first measure, you could try something such as the following:

 

Potential Saving Calculation = 

VAR _PotentialSaving = ( [Expected Usage] - [Actual Usage] ) * AVERAGE ( Forecast_Table [Price] )

RETURN 

IF ( ISBLANK ( [Actual Usage] ) , "" , _PotentialSaving ) 

 

For the second measure, try the same approach:

 

Forecast Accuracy = 

VAR _ForecastAccuracy = ABS ( ABS ( ( SUM ( Actual_Table [Expected_Usage] ) - [Actual Usage] ) ) / [Actual Usage] * 100 -100 )

RETURN 

IF ( ISBLANK ( [Actual Usage] ) , "" , _ForecastAccuracy) 

 

Hope this helps!

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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