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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Incorrect Measure total on a matrix if more than one rows

Hi Community,

 

I need help! I have this measure to calculated the no of days of leaves taken as following:

Leave days count: =
VAR startdate =
MAX ( 'Table'[leave start date] )
VAR enddate =
MAX ( 'Table'[leave end date] )
VAR calendartable =
FILTER ( Datedim, Datedim[Date] >= startdate && Datedim[Date] <= enddate )
return
COUNTROWS ( calendartable )
 
Issue is with measure total when there are more than one rows of leaves for an employee (Example Emp I in Nov):  The first part of the image is just displaying the counts based on leave start & leve end dates. Second part of the image is where there is issue with totals .
 
1 ACCEPTED SOLUTION
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

Let me talk about the reason for the error first, because you did not put the start and end date columns in second matrix, so that the measure can only get the largest date.

vjaneygmsft_0-1638948504208.png

So you need to define a context in the measure first, so that even if you don't put the start and end dates, it won't affect the result.

Like this:

Measure 2 = 
SUMX (
    ADDCOLUMNS (
        SUMMARIZE ( 'Table', [Emp], 'Table'[leave start date], 'Table'[leave end date] ),
        "diff",
            COUNTROWS (
                FILTER (
                    Datedim,
                    Datedim[Date] >= EARLIER ( 'Table'[leave start date] )
                        && Datedim[Date] <= EARLIER ( 'Table'[leave end date] )
                )
            )
    ),
    [diff]
)

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

 

 

View solution in original post

4 REPLIES 4
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

Let me talk about the reason for the error first, because you did not put the start and end date columns in second matrix, so that the measure can only get the largest date.

vjaneygmsft_0-1638948504208.png

So you need to define a context in the measure first, so that even if you don't put the start and end dates, it won't affect the result.

Like this:

Measure 2 = 
SUMX (
    ADDCOLUMNS (
        SUMMARIZE ( 'Table', [Emp], 'Table'[leave start date], 'Table'[leave end date] ),
        "diff",
            COUNTROWS (
                FILTER (
                    Datedim,
                    Datedim[Date] >= EARLIER ( 'Table'[leave start date] )
                        && Datedim[Date] <= EARLIER ( 'Table'[leave end date] )
                )
            )
    ),
    [diff]
)

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

 

 

Anonymous
Not applicable

@v-janeyg-msft Thank you for explaining the reason for the issue.

amitchandak
Super User
Super User

@Anonymous , Try a measure like

 

sumx('Table', datediff('Table'[leave start date] , 'Table'[leave end date], day))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak  sorry that doesn't work for me.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.