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
Vatz8
Frequent Visitor

SUMX Calculation

 

Hi, 

I am trying to add consecutive punch hours in consecutive hours column  if the difference between the current row and the previous row is less than 1.5. I have already added an index column and I am using the Sumx formula given below. I am however getting an error with the calculation as can be seen here. Can anyone please let me know what the issue might be and what can be done?

post.png

 

Screenshot 2022-09-21 110808.png

4 REPLIES 4
v-chenwuz-msft
Community Support
Community Support

Hi @Vatz8 ,

 

A simple workaround, change the earlier(vm_moc[employee]) to max(vm_moc[employee]).

 

Try this code:

Consecutive hours =
SUMX (
    FILTER (
        ALLSELECTED ((vw_moc),
        vw_moc[employee] = max ( vw_moc[employee] )
            && (
                LOOKUPVALUE ( vw_moc[TimeDifference], vw_moc[Index], vw_moc[Index] )
                    - LOOKUPVALUE ( vw_moc[TimeDifference], vw_moc[Index], vw_moc[Index] - 1 )
            ) < 1.5
            && vw_moc[Index]
                > LOOKUPVALUE ( vm_moc[TimeDifference], vw_moc[Index], vw_moc[Index] - 1 )
    ),
    vw_moc[punch_hours]
)

 

 

Best Regards

Community Support Team _ chenwu zhu

 

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

This formula is returning with an error, probably due to the allselected()

daXtreme
Solution Sage
Solution Sage

First, you should refrain from using

daXtreme_0-1663821714554.png

Use variables instead. Please go to EARLIER – DAX Guide and peruse the article. Then change your code accordingly.

 

Also, please refrain from using one-table models. Such a (bad) practice will create so many problems in no time that you'll be forced into doing it the right way anyway (and will be wasting time). Please read about how to create correct models that in fact do calculate what you want them to instead of giving you - RANDOMLY - wrong figures: Understand star schema and the importance for Power BI … (bing.com)

Hi, 

can you please provide a solution to this problem?

 

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.