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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Anonymous
Not applicable

Countrows incorrect

Hi Community,

 

I have a measure to calculate total leaves taken which excludes weekends & public holidays. Countrows is not yeilding correct result.

For example in following,  In Dec, emp 12 took 21 leaves not 13

ExcelPBI_0-1642146848463.png

My sample PBI file:  https://1drv.ms/u/s!Ag919_pO_UKrgSjIVaFeSDgQFcn1?e=lCvuJq

 

Your help is very much appreciated.

Thanks

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try like

 

Total Leaves = 
CALCULATE( SUMX (
    ADDCOLUMNS (
        SUMMARIZE ( 'Emp Leave', 'Emp Leave'[emp_code], 'Emp Leave'[date_start], 'Emp Leave'[date_end] ),
        "diff",
            COUNTROWS (
                FILTER (
                    Datedim,
                    Datedim[Date] >=  ( 'Emp Leave'[date_start] )
                        && Datedim[Date] <=  ( 'Emp Leave'[date_end] ) && datedim[working days]=1
                )
            )
    ),
    [diff]
), CROSSFILTER('Emp Leave'[date_start],datedim[Date],None))
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

View solution in original post

2 REPLIES 2
BarnabasToth
Resolver I
Resolver I

Hi there,

A little tweak on the model, creating a table like this (better to be created at source though):

Emp Leave RelevantDays = -- SELECTCOLUMNS not necessary
SELECTCOLUMNS (
    GENERATE (
        'Emp Leave',
        DATESBETWEEN( datedim[Date], 'Emp Leave'[date_start], 'Emp Leave'[date_end] )
    ),
    "emp_code", 'Emp Leave'[emp_code],
    "RelevantDates", 'datedim'[Date]
)

 Can make the DAX code easier:

Solution 2 = 
CALCULATE (
    COUNTROWS ( 'Emp Leave RelevantDays' ),
    datedim[working days] = 1
)

See file here

Regards

amitchandak
Super User
Super User

@Anonymous , Try like

 

Total Leaves = 
CALCULATE( SUMX (
    ADDCOLUMNS (
        SUMMARIZE ( 'Emp Leave', 'Emp Leave'[emp_code], 'Emp Leave'[date_start], 'Emp Leave'[date_end] ),
        "diff",
            COUNTROWS (
                FILTER (
                    Datedim,
                    Datedim[Date] >=  ( 'Emp Leave'[date_start] )
                        && Datedim[Date] <=  ( 'Emp Leave'[date_end] ) && datedim[working days]=1
                )
            )
    ),
    [diff]
), CROSSFILTER('Emp Leave'[date_start],datedim[Date],None))
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

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.