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
Anonymous
Not applicable

How can I count the numer of rows filtering by two dates?

Good afternoon everyone,

 

This table is named "employees"

Captura.PNG

 

So I have the following problem:

 

The column "Fin.Ult Contr" shows the date when the employee was hired and the column "Nueva Fecha" shows when the same employee was fired. 

 

I'd like to know how many employees do I had working when I make a date filter selecting a minimum date (when the employees got hired) and a maximum date (when the employees got fired)

 

Is it necessary to create a calendar table to connect that two columns?

 

Many thanks in advance,

 

Kind regards,

Adrian

 

1 ACCEPTED SOLUTION

@Anonymous ,

 

I apologize for the mistake above, please modify the measure as below

Result =
VAR Min_Date =
    CALCULATE ( MIN ( Calendar[Date] ), ALLSELECTED ( Calendar ) )
VAR Max_Date =
    CALCULATE ( MAX ( Calendar[Date] ), ALLSELECTED ( Calendar ) )
RETURN
    COUNTROWS (
        FILTER (
            employees,
            employees[Fin.Ult Contr] >= Min_Date
                && employees[Nueva Fecha] <= Max_Date
        )
    )

Community Support Team _ Jimmy Tao

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

View solution in original post

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

You can create a measure using dax below:

Result =
VAR Min_Date =
    CALCULATE ( MIN ( Calendar[Date] ), ALLSELECTED ( Calendar ) )
VAR Max_Date =
    CALCULATE ( MAX ( Calendar[Date] ), ALLSELECTED ( Calendar ) )
RETURN
    COUNTROWS (
        FILTER (
            employees,
            employees[Fin.Ult Contr] <= Min_Date
                && employees[Nueva Fecha] >= Max_Date
        )
    )

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

Hi @v-yuta-msft,

 

I've tried your DAX but as you can see, it's not throwing any data back even when all the dates are selected: 

Captura.PNG

 

I don't know but problably it's because of how the tables are linked currently (Fin Ult.Contr & Nueva Fecha Corregida are both linked to Date):Captura.PNG

 

By the way, I've tried the following measure with both of the links being inactive but again, it's not throwing back back the result I'm looking for: 

 

 
EMPLEADOS TOTALES =
CALCULATE( COUNTROWS('DETALLES EMPLEADO'); FILTER( VALUES( 'DETALLES EMPLEADO'[Fin Ult.Contr]); 'DETALLES EMPLEADO'[Fin Ult.Contr]<= MAX('CALENDARIO GENERAL'[Date])); FILTER( VALUES('DETALLES EMPLEADO'[NUEVA FECHA CORREGIDA]);'DETALLES EMPLEADO'[NUEVA FECHA CORREGIDA]>= MIN('CALENDARIO GENERAL'[Date])))
 
Many thanks for your response! 
Hope you can help me..
 
Cheers! 
Adrian

@Anonymous ,

 

I apologize for the mistake above, please modify the measure as below

Result =
VAR Min_Date =
    CALCULATE ( MIN ( Calendar[Date] ), ALLSELECTED ( Calendar ) )
VAR Max_Date =
    CALCULATE ( MAX ( Calendar[Date] ), ALLSELECTED ( Calendar ) )
RETURN
    COUNTROWS (
        FILTER (
            employees,
            employees[Fin.Ult Contr] >= Min_Date
                && employees[Nueva Fecha] <= Max_Date
        )
    )

Community Support Team _ Jimmy Tao

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

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.