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 August 31st. Request your voucher.

Reply
Gerosaki88
New Member

SUMX() and Filter an operation

Hi people... I'm having a problem with a DAX formula.

 

I'm trying to get the absolute difference between two columns ( "HH ASIGNADAS" and "HH EJECUTADAS")

 

Captura de pantalla 2024-03-01 114355.png

 

Now, in those cases in which there is no value in the "HH ASIGNADAS" column, said difference should not be made. To achieve this I'm using the following expression (measure):

 

DIF = SUMX(VALUES(ENTREGABLES[CODIGO ENTREGABLE]), IF(HASONEVALUE(BBDD1[HH ASIGNADAS]),[DIF_ABSOLUTA], BLANK()))
 
Where:
 
DIF_ABSOLUTA = ABS(SUM(BBDD1[HH ASIGNADAS])-SUM(HH_ejecutadas_minedoc[Horas_ejecutadas]))
 
BBDD1[HH ASIGNADAS]) = Hours that were assigned to professionals.
 
HH_ejecutadas_minedoc[Horas_ejecutadas] = Hours that were executed by professionals
 
And ENTREGABLES[CODIGO ENTREGABLE] is a column that contains all the codes of the documents on which the professionals work.
 
Locally the expression is working, but it is not giving me a final result (which is the value I am actually looking for). If in the "IF" condition I leave "BLANK()" for when it is not met, I get "BLANK" as a total sum, and line by line it looks like the image above.
 
Captura de pantalla 2024-03-01 113934.png
 
Now, if for example I change the "BLANK()" to "0", the table looks like this:
 
Captura de pantalla 2024-03-01 114120.png
 
And the final result gives me zero:
 
Captura de pantalla 2024-03-01 114311.png
The same thing that happens with zero happens if I put a one for example.
 
I hope the problem is clear. Any help is welcome.

Thank you very much and greetings
 
Additional comments: I also tried using the CALCULATE() function but nothing happens
 
DIF_CALCULATE = SUMX(VALUES(ENTREGABLES[CODIGO ENTREGABLE]), CALCULATE([DIF_ABSOLUTA], BBDD1[HH ASIGNADAS] <> BLANK()))
 
Directly it is as if it does not apply any filter and does the operation regardless of whether "HH ASIGNADAS" has information or not
 
Captura de pantalla 2024-03-01 114939.png
 
In the latter case it doesn't matter if I use "BLANK()" or zero, etc.
 
The data model:
 
Captura de pantalla 2024-03-01 121612.png
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I'd try this and tweak as necessary:

DIF =
SUMX (
    VALUES ( ENTREGABLES[CODIGO ENTREGABLE] ),
    VAR _Asignadas = CALCULATE ( SUM ( BBDD1[HH ASIGNADAS] ) )
    VAR _Ejutadas = CALCULATE ( SUM ( HH_ejecutadas_minedoc[Horas_ejecutadas] ) )
    RETURN
        IF (
            ISBLANK ( _Asignadas ), /*|| ISBLANK ( _Ejutatas ),*/
            BLANK (),
            ABS ( _Asignadas - _Ejutadas )
        )
)

I've included a commented-out part that you can include if you want to check both are nonblank.

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

I'd try this and tweak as necessary:

DIF =
SUMX (
    VALUES ( ENTREGABLES[CODIGO ENTREGABLE] ),
    VAR _Asignadas = CALCULATE ( SUM ( BBDD1[HH ASIGNADAS] ) )
    VAR _Ejutadas = CALCULATE ( SUM ( HH_ejecutadas_minedoc[Horas_ejecutadas] ) )
    RETURN
        IF (
            ISBLANK ( _Asignadas ), /*|| ISBLANK ( _Ejutatas ),*/
            BLANK (),
            ABS ( _Asignadas - _Ejutadas )
        )
)

I've included a commented-out part that you can include if you want to check both are nonblank.

Can I ask you a question? Why did you use Calculate in this expression and not just SUM?

 

VAR _Asignadas = CALCULATE ( SUM ( BBDD1[HH ASIGNADAS] ) )

Context transition. I want the SUM to be calculated within the context of the current ENTREGABLES[CODIGO ENTREGABLE] row of SUMX.

 

Further reading:

https://www.sqlbi.com/articles/understanding-context-transition/

https://www.sqlbi.com/articles/understanding-context-transition-in-dax/

It worked!! Thank you very much!!

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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