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

DIVIDE DAX with error when using 2 numerators

Hi, I'm trying to calculate a percentage index of goal/accomplished.

 

But the divide function is causing defect in matrix display when using 2 numerators in the divide function.

 

For a reason I don't know, when use 2 numerators in divide formula, the page filter "year" doesn't works. The matrix show me all dates avaiable in my date dimension table.

 

The formula is:

 

DIVIDE (number1 - constant, number2 - constant)

 

Where the constant is represented by the measure [LINHA BASE MARG] with value 0.25

 

See:

erro.png

 

When I use only one numerator, it works as expected (except by the fact that I have the wrong result because is lacking one value in numerator divide formula):

 

esperado.PNG.png

 

Any solution?

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

I see.

If you return ICM,you will find that the measure without constant value still showing result only for 2021:

vkellymsft_0-1625553046073.png

But the measure with constant value are showing values with all the years:

vkellymsft_1-1625553091584.png

It means that the if condition doesn work in your measure,so try to modify your measure as below:

 

 

ICM MARG = 
VAR _ARG1 = [% MARGEM SM] - [LINHA BASE MARG]
VAR ARG2 = [META MARG] - [LINHA BASE MARG]
VAR ICM = DIVIDE(_ARG1, ARG2) //verificar porque quando o numerador do divide tem um número sendo subtraído a matriz perde o filtro do ano
VAR RESUL = IF(ICM < 0, BLANK(), ICM)
RETURN  RESUL

 

 

And you will see:

vkellymsft_2-1625553272745.png

The result only contains the value in 2021.

 

 

Best Regards,
Kelly

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

View solution in original post

16 REPLIES 16
aj1973
Community Champion
Community Champion

Hi @Anonymous 

add VAR for each equation then use them in Divide:

var _1 = A-B

var _2 = C-D

var _Divide = DIVIDE( _1 ,_ 2 , 0)

RETURN

_Divide

 

or use _Result = (A-B) / (C-D)

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

The issue persist:

 

ERROR.png

 

aj1973
Community Champion
Community Champion

Can you verify and RETURN 

ARG1

ARG2

and show the result please?

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

Arg1 and Arg2 below:

 ERRO2.PNG

 

There isn't problem with the arg values.

 

I've found if I set the year filter in visual, it works. But I already have a year filter defined in the page filters.

 

aj1973
Community Champion
Community Champion

From your visual I can see ARG1 < 0 and ARG2 > 0 when you divide them the result ICM is always < 0 .

In your IF statment 

aj1973_0-1625154365049.png

 

you wanted to RETURN 0 if ICM < 0. That<s why you see 0 in your visual.

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

The zero is not the problem, show zero to years 2016, 2017, 2018, etc when I have a filter defined to 2021 is the problem. I don't wanna see values to other years.

Here a similar discussing: https://community.powerbi.com/t5/Desktop/Slicer-not-filtering-measure-with-constant-value-over-date-...

aj1973
Community Champion
Community Champion

Then you need to use SELECTEDVALUE for all your measures involved in DIVIDE.

May be if you can share your file I can help you better.

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

Link to download the pbi file: https://we.tl/t-t7fKRwLDjP

aj1973
Community Champion
Community Champion

Here are the mistakes:

1- in your Matrix you are using fields that have inactive relationship with each others like using DATA FISCAL with SUPERMETA 2021

2- The inactive relationship between Tables are Many to Many (Wrong)
3- You see 0% for all years but 2021, because in your tabel "SUPERMETA 2021" you don't have data from the other years

4- most of the measures if not all where you are using USERELATIONSHIP are not correct since the relationship is Many to Many

5- The model (Tables and relationships) is not good. There is no star schema in place, Data fiscal....

6- In your model i see your using 3 Tables for your visuals, why uploading the rest of the Tables if you are not going to use them!

 

I recommend making some order in your file before going any further...

 

   

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

@aj1973 the page "SUPERMETA FAT 2021" works with same tables and works like a charm. There isn't problem with the relationship between the data.

 

The issue only occurs when a CONSTANT (fixed number) is added to the numerator of divide of my measure in page "SUPERMETA MARG 2021".

 

Like I said in description, when it doesn't have the constant in formula, everything goes well, but I need that constant, so I cant left the formula without it.

Hi @Anonymous ,

 

After checking your sample data,while using the 2 formula below:

ICM MARG1 = 
var ARG1=[% MARGEM SM]
VAR ARG2 = [META MARG] - [LINHA BASE MARG]
VAR ICM = DIVIDE(ARG1, ARG2) //verificar porque quando o numerador do divide tem um número sendo subtraído a matriz perde o filtro do ano
VAR RESUL = IF(ICM < 0, 0, ICM)
RETURN RESUL
ICM MARG = 
VAR _ARG1 = [% MARGEM SM] - [LINHA BASE MARG]
VAR ARG2 = [META MARG] - [LINHA BASE MARG]
VAR ICM = DIVIDE(_ARG1, ARG2) //verificar porque quando o numerador do divide tem um número sendo subtraído a matriz perde o filtro do ano
VAR RESUL = IF(ICM < 0, 0, ICM)
RETURN RESUL

When you move the slicer of matrix to the same year.They both have data:

vkellymsft_0-1625474546395.png

So where is the problem?

 

Best Regards,
Kelly

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

Anonymous
Not applicable

Hi @v-kelly-msft . I have a page filter defined to 2021 and the matrix show values to years 2016, 2017, 2018, etc, when I put a constant ( [LINHA BASE MARG] = 0.25 ) in numerator of divide. I don't wanna see values to other years.

I can't understand why the page filter doesn't works when I have a constant in numerator of divide. 🤷‍♂️

 

If the constant doesn't be there in numerator of divide, the page filter works decently.

Hi @Anonymous ,

 

I see.

If you return ICM,you will find that the measure without constant value still showing result only for 2021:

vkellymsft_0-1625553046073.png

But the measure with constant value are showing values with all the years:

vkellymsft_1-1625553091584.png

It means that the if condition doesn work in your measure,so try to modify your measure as below:

 

 

ICM MARG = 
VAR _ARG1 = [% MARGEM SM] - [LINHA BASE MARG]
VAR ARG2 = [META MARG] - [LINHA BASE MARG]
VAR ICM = DIVIDE(_ARG1, ARG2) //verificar porque quando o numerador do divide tem um número sendo subtraído a matriz perde o filtro do ano
VAR RESUL = IF(ICM < 0, BLANK(), ICM)
RETURN  RESUL

 

 

And you will see:

vkellymsft_2-1625553272745.png

The result only contains the value in 2021.

 

 

Best Regards,
Kelly

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

Anonymous
Not applicable

Awesome! Thank you!

aj1973
Community Champion
Community Champion

My freind this is your Matrix without Values

aj1973_0-1625171818190.png

 

Please don't tell me that there is nothing wrong.

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

NEWS:
my measure use a constant value, then it is going to show for all dates regardless how I filter it because the measure is always returning a value. But, how to solve this?

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.