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

Total SUM fails - all is fine on each row

Hi,
I've spent way too much time on this now, so I have to ask for some help.

I have 2 tables:
data: holds data from git commits
Dates: holds a full range of dates
The tables are related via Dates[date] ==> data[commiterDate]

This code works for counting the number of work days in selected date span on each row.
(The user can set a date span via a date slider control).

 

 

Sum wrk.days = 
COUNTROWS(
    FILTER(
        DATESBETWEEN(Dates[Date], MIN(data[committerDate]), MAX(data[committerDate])),
        WEEKDAY(Dates[Date], 2) < 6
    )
)

 

 


My problem is that the total summary at the bottom of the table fails.
I think I have to use SUMX in some way, but I can't figure out how.

petluo_0-1642019672548.png

Sum should be 7...


I hope someone can help me.

Best regards
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

If good.spread and oneCommitter overlapped a day, then the total makes sense.

 

If you want to sum the rows, then you need to iterate over commiterid somehow. One option:

Commiter Work Days = SUMX ( VALUES ( data[committerId] ), [Sum wrk. days] )

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

If good.spread and oneCommitter overlapped a day, then the total makes sense.

 

If you want to sum the rows, then you need to iterate over commiterid somehow. One option:

Commiter Work Days = SUMX ( VALUES ( data[committerId] ), [Sum wrk. days] )

Thank you, it works!

Just the kind of simple solution I was looking for. 👍

 

The code now:

Wrk.days = 
SUMX( 
    VALUES(data[committerId]), 
    [Wrk.days row count] 
)

---

Wrk.days row count = 
VAR cr = 
COUNTROWS(
    FILTER(
        DATESBETWEEN(Dates[Date], [MinDate], [MaxDate]),
        WEEKDAY(Dates[Date], 2) < 6
    )
)
RETURN 
IF(
    cr > 0,
    cr,
    1
)

 

smpa01
Super User
Super User

@petluo  can you try this

Measure =
SUMX (
    SUMMARIZE (
        ADDCOLUMNS (
            data,
            "daysCount",
                CALCULATE (
                    COUNT ( Dates[Date] ),
                    (
                        FILTER (
                            DATESBETWEEN (
                                Dates[Date],
                                CALCULATE ( MIN ( data[committerDate] ), ALLEXCEPT ( data, data[committerid] ) ),
                                CALCULATE ( MAX ( data[committerDate] ), ALLEXCEPT ( data, data[committerid] ) )
                            ),
                            WEEKDAY ( Dates[Date], 2 ) < 6
                        )
                    )
                )
        ),
        data[committerid],
        [daysCount]
    ),
    [daysCount]
)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
petluo
Frequent Visitor

Thank you!

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.