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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
floralsnow
Frequent Visitor

DAX: subtraction work but not division

I'm having difficulty understanding how you calculate when comparing two different tables.

I created a simple mockup which exemplifies what I'm dealing with.

floralsnow_0-1648457919316.png

 

I have two tables which are connected to a calendar table.

I have a measure where I'm trying to divide two values where each of them exist in their own table.

 

I created these to make it easier to refer to the different values.

Cost = SUM('R-Cost'[Amount Eur])
Revenue = SUM('R-Revenue'[External Revenues EUR])
 
I then try to calculate the margin with this measure
Margin = DIVIDE('Calculations'[Cost],'Calculations'[Revenue])
but this results in zeroes! I was thinking that maybe my relationships are wrong, but, I am able to subtract.

This measure works fine for example:
Diff =
VAR _Cost = 'Calculations'[Cost]
VAR _Revenue = 'Calculations'[Revenue]
VAR _Diff = (_Revenue - _Cost)
RETURN _Diff
 
So how come subtraction works but not division?
 
floralsnow_1-1648458331374.png

 

 I have googled like crazy but I just don't understand what I'm missing.

 

1 ACCEPTED SOLUTION
Aditya_Meshram
Solution Supplier
Solution Supplier

Hi @floralsnow 
It may be due to the Y-Axis Scale. Since you have scale of Y-Axis set at the hundred million level, the result of the division which is a fractional value between 0 and 1(for example, at the starting point it is 54M/221M which is about 0.24), is too small to be plotted on this line chart. You can check the actual values by setting the display units of the data label to none.

View solution in original post

8 REPLIES 8
tamerj1
Super User
Super User

@floralsnow 
I believe I know what the problem is. You are using columns as values in your schedule which is a common mistake. When added as values, columns shall be only added as measures. In your example you can use the measuures:
[Cost] & [Reveniew] instead of the the columns
1.png

I switched between using the columns directly in the visualisation and using measures, but I could see no difference.

 

Your post intrigued me and I tried to find more information about this. But the only real difference I could find, both in this community and elsewhere on the web, was the difference between using a calculated column and a measure, where it was stated that a measure is preferable unless you need to filter on the data.

 

However, in this case I didn't use a calculated column, only one of the columns which are in the table from the beginning.

 

How come it can be negative to use such a column in your visualisation?

Aditya_Meshram
Solution Supplier
Solution Supplier

Hi @floralsnow 
It may be due to the Y-Axis Scale. Since you have scale of Y-Axis set at the hundred million level, the result of the division which is a fractional value between 0 and 1(for example, at the starting point it is 54M/221M which is about 0.24), is too small to be plotted on this line chart. You can check the actual values by setting the display units of the data label to none.

ok, I changed Data Label's display units to "none" and got this

 

floralsnow_0-1648469241185.png

 

I could then change it to percentage, and get the correct value. So I think it's correct now!

That's great!🙂

tamerj1
Super User
Super User

@floralsnow 
The 2nd formula looks to me like a calculated column not a measure. Measres have no row context and you cannore directly reference the columns.
If you create the first formula as a measure not a calculated column it should work. At least it should give some values. Of course I'm assuming the date in the visual is from the date tabl?

Do you mean "Margin = DIVIDE('Calculations'[Cost],'Calculations'[Revenue])"?
I created it by doing "New Measure"

floralsnow_0-1648466380885.png

It's still a calculated column?

Ok this is called a measure. When refering to measures inside a formula the standard is to refer directly to the measure name with referencing the table name so we anyone reads the code can distinguish beteen colums and measure. For exsmple

Table[Column]
[Measure]

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.