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
bebeto
Helper III
Helper III

Cumulative measure in past years and months

Hello,

 

I am buiding a report from an ERP tables. I have an employees table in which I know data_from and data_to. It also has an Active columns.

 

What I want to paint in a chart is the number of employees active by past years and months. I have created a DimDate table and related with my employees table, 2 relationships, with date_from and date_to.

 

¿How can I get this information?

 

Thanks in advance!

3 ACCEPTED SOLUTIONS

@bebeto

 

Thanks for the sample data. I create a calendar table and a measure with following formula.

But I’m confused that why there is only 1 active employee (lker) in April. Roberto’s date_to is 30/04/2016 which is the last day in April.

DimFecha = CALENDAR ( MIN ( Empleados[Fecha_incorporacion] ), TODAY () )
EmpleadosActivosPeriodo =
CALCULATE (
    COUNTROWS ( Empleados ),
    FILTER (
        Empleados,
        Empleados[Fecha_incorporacion] <= MAX ( DimFecha[Date] )
            && Empleados[date_to] >= MAX ( DimFecha[Date] )
    )
)

Cumulative measure in past years and months.jpg

 

Best Regards,
Herbert

View solution in original post

@bebeto

 

You can inactive the needed relationships and use USERELATIONSHIP function when you need it. Following two articles may help you.

http://sqlblog.com/blogs/marco_russo/archive/2013/10/01/using-userelationship-function-in-measures-a...

http://sqlblog.com/blogs/marco_russo/archive/2010/02/09/how-to-relate-tables-in-dax-without-using-re...

Cumulative measure in past years and months_2.jpg

 

For you second question, please try with following modified measure formula.

EmpleadosActivosPeriodo =
IF (
    MIN ( DimFecha[Date] ) <= TODAY (),
    CALCULATE (
        COUNTROWS ( Empleados ),
        FILTER (
            Empleados,
            Empleados[Fecha_incorporacion] <= MAX ( DimFecha[Date] )
                && Empleados[date_to] >= MAX ( DimFecha[Date] )
        )
    ),
    BLANK ()
)

 

Best Regards,

Herbert

View solution in original post

@bebeto

 

Since you want to always show the data for current year without typing/selecting anything, you need to create this “current year” table to use on the axis of the visuals.

 

Best Regards,

Herbert

View solution in original post

23 REPLIES 23

I have created the measure as you said:

 

EmpleadosActivosPeriodo =
CALCULATE
(
COUNTROWS(Empleados);
FILTER(Empleados;Empleados[Fecha_incorporacion] <= MIN(DimFecha[Date]) && Empleados[date_to] > max(DimFecha[Date])
))

 

But the result is "Blank"

 

I don't understand "In this case I have a second date table to use on the axis of the visuals, make sure you do not create a relationship between the 2."

 

I have a DimFecha table (as a calendar) and is related with my employees table with two relationships (date_from and date_to)

 

What is wrong?

 

 

Vvelarde
Community Champion
Community Champion

What happen if you change

 

EmpleadosActivosPeriodo =
CALCULATE
(
COUNTROWS(Empleados);
FILTER(Empleados;Empleados[Fecha_incorporacion] >= MIN(DimFecha[Date]) && Empleados[date_to] <= max(DimFecha[Date])
))




Lima - Peru

The relationships will filter out the data based on the relationship so you should remove the relationships. By thw way the calculation will not give you a cumulative but employees within the time range. 

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.