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

DAX formula calculation gives wrong value!?

Hello,

I run into a dilemma with a calculation in DAX that works fine for one column and gives wrong results if applied to a different column.

I have this data set , where STC, STCR, LTC and LTCR are measures. STC, STCR, LTC numbers are correct based on the formula applied. Strangely, the LTCR gives wrong results (close but not right).

Cristian1_0-1669310183166.png

Here are the measures used:

STC = ([SecondLatestValue] - [LastValue]) * 1.5
STCR = DIVIDE([LastValue] - VALUES('Piping UT ex'[Tmin (mm)]), [STC])
LTC = ([FirstValue] - [LastValue]) * 1.33
LTCR = DIVIDE([FirstValue] - VALUES('Piping UT ex'[Tmin (mm)]), [LTC]).
All formulas give the right result but the LTCR! For first row it should be 19.79, not 19.84. Same with the rest of the records for LTCR. Does anybody encountered this problem?

 

1 ACCEPTED SOLUTION
v-rongtiep-msft
Community Support
Community Support

Hi @Anonymous ,

There seems nothing error with the measure.

 

LTCR = DIVIDE([FirstValue] - MIN('Piping UT ex'[Tmin (mm)]), [LTC])

 

 

We can calculate the ([FirstValue] - MIN('Piping UT ex'[Tmin (mm)]) first.

 

This part calculates well.

vpollymsft_1-1669355427870.png

 

 

Let me check the measure [LTC].

 

 

LTC = ([FirstValue] - [LastValue]) * 1.33

 

 

First LTC result is (12.9-12.54)=0.36. 0.36*1.33=0.4788.

 

Then 9.5/0.4788=19.84.

 

If you want the reslut  19.84 change to be 19.79. Please try to change the measure [LTC].

 

 

LTC = var _1= ([FirstValue] - [LastValue]) * 1.33 return ROUND(_1,2)

 

 

vpollymsft_0-1669355382950.png

 

 

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

20 REPLIES 20
v-rongtiep-msft
Community Support
Community Support

Hi @Anonymous ,

There seems nothing error with the measure.

 

LTCR = DIVIDE([FirstValue] - MIN('Piping UT ex'[Tmin (mm)]), [LTC])

 

 

We can calculate the ([FirstValue] - MIN('Piping UT ex'[Tmin (mm)]) first.

 

This part calculates well.

vpollymsft_1-1669355427870.png

 

 

Let me check the measure [LTC].

 

 

LTC = ([FirstValue] - [LastValue]) * 1.33

 

 

First LTC result is (12.9-12.54)=0.36. 0.36*1.33=0.4788.

 

Then 9.5/0.4788=19.84.

 

If you want the reslut  19.84 change to be 19.79. Please try to change the measure [LTC].

 

 

LTC = var _1= ([FirstValue] - [LastValue]) * 1.33 return ROUND(_1,2)

 

 

vpollymsft_0-1669355382950.png

 

 

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Anonymous
Not applicable


Thank you, probably my test table had it set up with the right decimals and here was not rounded. Much appreciate all those who responded, @KNP , @katika555 , @v-rongtiep-msft. Lesson learned for the future. Question: Does it matter if I use VALUES instead of MIN, what would be the disadvantage?
 
 

You're welcome.

VALUES returns a table of distinct values.

MIN returns a scalar value.

VALUES will likely fail if you put the measue in a different visualisation.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
Anonymous
Not applicable

@KNP Thank you.

katika555
Resolver I
Resolver I

katika555_0-1669321805566.png

If our dataset is like this picture, you dont need any Values just Divide, or share your file.

Yeah, but @Anonymous is trying to add a measure, not a column.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

katika555_0-1669323385739.png

Same with measure 🙂

Yep, except I think something is going on with the data because the measure is simple.

 

@Anonymous - post data, PBIX and even code from advanced editor could help. Hide any sensitive info. Something is going on in the data/calculations for you to think it is incorrect. We can't answer without further info.

 

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
Anonymous
Not applicable

The calculation is correct, your LTC for the top value in the example is 0.4788 not 0.48. (add decimal places to your measure to verify)

If you manually do the calculation with that value, you'll see it is right. 

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
KNP
Super User
Super User

Where does 'Piping UT ex'[Tmin (mm)] column come from? A seperate table?

If yes, would be good to include a screenshot of your data model so we can understand the relationships.

If it's the same table then @katika555 answer should solve the issue for you.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
Anonymous
Not applicable

It is one simple table, no relationships involved

Cristian1_0-1669316919131.png

 

Ok, always best to post this detail at the begining. 

Try to include sample data as data (not screenshot) as it makes it easier to provide an answer.

 

Depending on where else you use the measure, this may give you what you want.

LTCR =
DIVIDE (
    [FirstValue]
        - MIN ( 'Piping UT ex'[Tmin (mm)] ),
    [LTC]
)

 

In the row context of that table, this will work fine.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
Anonymous
Not applicable

OK, I omitted to explain a bit better, but considering the issue (calculation result) that it works for one measure but it gives wrong results for another with same formula.

Still I changed values with min and there is no change in results. I don't know how to add the pbix or data sample to this discussion.

PBIX would need to be shared via OneDrive or similar.

Data you can just copy and paste straight in here.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
katika555
Resolver I
Resolver I

Why are you using  VALUES function?
just [Tmin (mm)] ??

Anonymous
Not applicable

Tmin is a column, not a measure, and if you don't use values, it gives an error.

Cristian1_0-1669314942652.png

 

Remove the bracket.

KNP_0-1669315366395.png

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
Anonymous
Not applicable

Cristian1_0-1669316437095.png

Still error. It still not my issue here. with values or not, calculation is wrong in DAX! 

That's what I assumed the case may be, so please refer to my first reply. 

Need more detail about your model/relationships to answer this effectively.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

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.