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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
MVCPA
Frequent Visitor

Help with DAX Measure - Sum with condition

Hi all!,

 

I have table that contains a list of employees and their timesheet entries. Currently, my manager wants to apply a logic and show it up in a Matrix.

 

Logic: IF Employee A's all hours except "Normal Time" >= 164, then "Normal Time" should show zero. Else Show the difference between Employee A's all hours except "Normal Time" vs hours that are "Normal Time".
PS: They also want that in the totals.

 

 

test1.jpg

Here's an example:

 

 

As seen in the Screenshot, Karen's hours <> "Normal Time" = 87.2 while the "Normal Time" is 174.8.
The expected result should be:
-Time Categories A,B,C,D,E,F,G should show the same. 
-Normal hours should show as 87.6

- Total Hours should be 174.8

 

I am really not sure if I shoud manipulate the data using DAX or Using M Query. I've been on this for days now, any help will be appreciated. Thank you!

1 ACCEPTED SOLUTION

Hi @MVCPA ,

 

Sorry for the delay in response!!

 

Below is the updated measure which is showing normal time only for indirect for karen employee. Attached pbix file for reference.

 

Expected Value =
SUMX(
    SUMMARIZECOLUMNS(
        employee[crc27_employee],
        'Time type'[crc27_timetype]
    ),
    VAR CurrentHours =
        CALCULATE(
            SUM('Sample'[crc27_hours])
        )
    VAR HasData =
        NOT ISBLANK(CurrentHours)
    VAR NonNormalHours =
        CALCULATE(
            SUM('Sample'[crc27_hours]),
            REMOVEFILTERS('Time type'),
            NOT('Time type'[crc27_timetype] IN {"Normal Time"})
        )
    RETURN
        IF(
            HasData,
            IF(
                NonNormalHours >= 164.67,
                SWITCH(
                    TRUE(),
                    SELECTEDVALUE('Time type'[crc27_timetype]) = "Normal Time", 0,
                    CurrentHours
                ),
                SWITCH(
                    TRUE(),
                    SELECTEDVALUE('Time type'[crc27_timetype]) = "Normal Time",
                    ABS(NonNormalHours - CurrentHours),
                    CurrentHours
                )
            ),
            BLANK()
        )
)
 
 
vsathmakuri_0-1762239748821.png

Please review the output and let us know if you still need any further assistance here.

 

Thanks & Regards,

Rekha Athmakuri.

View solution in original post

10 REPLIES 10
MVCPA
Frequent Visitor

Hi @Jihwan_Kim 

 

Thank you for your response. After some checks, the formula you gave me worked.

BUT I was given another requirement. Another filter was required in rows. I have attached a sample PIBX here.

MVCPA_0-1759808366272.png

 

Hi,
Please check the below if it provides the expected result.

Thank you.

Expected Value = 

SUMX(
    SUMMARIZECOLUMNS(employee[crc27_employee],'Time type'[crc27_timetype], Indirects[Indirects]),
    CALCULATE(
        IF(
            CALCULATE(
                SUM('Sample'[crc27_hours]),
                REMOVEFILTERS('Time type'),
                NOT ('Time type'[crc27_timetype] IN {"Normal Time"})
            )>=164.67,

            SWITCH(
                TRUE(),
                SELECTEDVALUE('Time type'[crc27_timetype]) = "Normal Time", 0,
                SUM('Sample'[crc27_hours])
            ),
            SWITCH(
                TRUE(),
                SELECTEDVALUE('Time type'[crc27_timetype]) = "Normal Time",
                    ABS(
                        CALCULATE(
                            SUM('Sample'[crc27_hours]),
                            REMOVEFILTERS( 'Time type'),
                            NOT ('Time type'[crc27_timetype] IN {"Normal Time"})
                        )
                        - SUM( 'Sample'[crc27_hours])
                    ),
                    SUM('Sample'[crc27_hours])
            )
        )
    )
    
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi @Jihwan_Kim !

 

Thank you for the providing a solution. I tried replicating it but I had this result:

MVCPA_0-1759966221023.png

 

As you can see Karen now shows "Normal Time" under "Direct". Am I missing something? Thanks again!

Hi @MVCPA ,

 

Sorry for the delay in response!!

 

Below is the updated measure which is showing normal time only for indirect for karen employee. Attached pbix file for reference.

 

Expected Value =
SUMX(
    SUMMARIZECOLUMNS(
        employee[crc27_employee],
        'Time type'[crc27_timetype]
    ),
    VAR CurrentHours =
        CALCULATE(
            SUM('Sample'[crc27_hours])
        )
    VAR HasData =
        NOT ISBLANK(CurrentHours)
    VAR NonNormalHours =
        CALCULATE(
            SUM('Sample'[crc27_hours]),
            REMOVEFILTERS('Time type'),
            NOT('Time type'[crc27_timetype] IN {"Normal Time"})
        )
    RETURN
        IF(
            HasData,
            IF(
                NonNormalHours >= 164.67,
                SWITCH(
                    TRUE(),
                    SELECTEDVALUE('Time type'[crc27_timetype]) = "Normal Time", 0,
                    CurrentHours
                ),
                SWITCH(
                    TRUE(),
                    SELECTEDVALUE('Time type'[crc27_timetype]) = "Normal Time",
                    ABS(NonNormalHours - CurrentHours),
                    CurrentHours
                )
            ),
            BLANK()
        )
)
 
 
vsathmakuri_0-1762239748821.png

Please review the output and let us know if you still need any further assistance here.

 

Thanks & Regards,

Rekha Athmakuri.

Hi @MVCPA ,

 

Could you please let us know if the provided response helped in resolving the issue. If you have any further questions we are happy to address.

 

Thank you!!

MVCPA
Frequent Visitor

Hi @Jihwan_Kim  ,

Thank you for your response. I really appreciate it.!This is how my model looks like:

 

MVCPA_3-1759791101087.png

 

I have patented my work to your example. I am just not lucky to have the same results as yours. As you can see, my expected results multiplied the non-"Normal Time" by 2. I am not sure why.
Please see the results:

 MVCPA_2-1759791030189.png


This is the measure that I used :

Expected Value =

SUMX(
    SUMMARIZECOLUMNS(employee[crc27_employee],'Hours Type'[Time Type]),
    CALCULATE(
        IF(
            CALCULATE(
                SUM(Hours[crc27_hours]),
                REMOVEFILTERS('Hours Type'),
                NOT ('Hours Type'[Time Type] IN {"Normal Time"})
            )>=164.67,

            SWITCH(
                TRUE(),
                SELECTEDVALUE('Hours Type'[Time Type]) = "Normal Time", 0,
                SUM(Hours[crc27_hours])
            ),
            SWITCH(
                TRUE(),
                SELECTEDVALUE('Hours Type'[Time Type]) = "Normal Time",
                    ABS(
                        CALCULATE(
                            SUM(Hours[crc27_hours]),
                            REMOVEFILTERS( 'Hours Type'[Time Type]),
                            NOT ('Hours Type'[Time Type] IN {"Normal Time"})
                        )
                        - SUM( Hours[crc27_hours])
                    ),
                    SUM(Hours[crc27_hours])
            )
        )
    )
   
)
 

 

 

Hi,

If it is OK, please recreate a sample pbix file, and please share your sample pbix file's link.

And then, I can try to look into it.

Thank you.

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
v-sathmakuri
Community Support
Community Support

Hi @MVCPA ,

 

Thank you for reaching out to Microsoft Fabric Community.

 

Thank you @Jihwan_Kim  and @danextian  for providing the response.

 

Could you please let us know if the provided response helped in resolving the issue. If you have any further questions we are happy to address.

 

Thank you!!

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the  below picture and the attached pbix file.

 

Jihwan_Kim_0-1759378867978.png

 

 

 

Jihwan_Kim_0-1759378680781.png

 

 

expected result measure: = 
SUMX (
    SUMMARIZECOLUMNS ( employee[employee], hours_type[hour_type] ),
    CALCULATE (
        IF (
            CALCULATE (
                SUM ( hours[hours] ),
                REMOVEFILTERS ( hours_type ),
                NOT ( hours_type[hour_type] IN { "Normal Time" } )
            ) >= 164,
            SWITCH (
                TRUE (),
                SELECTEDVALUE ( hours[hour_type] ) = "Normal Time", 0,
                SUM ( hours[hours] )
            ),
            SWITCH (
                TRUE (),
                SELECTEDVALUE ( hours[hour_type] ) = "Normal Time",
                    ABS (
                        CALCULATE (
                            SUM ( hours[hours] ),
                            REMOVEFILTERS ( hours_type ),
                            NOT ( hours_type[hour_type] IN { "Normal Time" } )
                        )
                            - SUM ( hours[hours] )
                    ),
                SUM ( hours[hours] )
            )
        )
    )
)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
danextian
Super User
Super User

Hi @MVCPA 

 

Please provide a workable sample data (not an image), your expected result from the same sample data and your reasoning behind. You may post a link to Excel or a sanitized copy of your PBIX (confidential data removed) stored in the cloud. Just as it takes time to prepare your sample data, it also takes time to come up with a solution.

 

This sticky post should serve as a guide:

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.