cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Syndicate_Admin
Administrator
Administrator

Number of days between dates distributed by months

Hello.

I'm new to Power BI and need help figuring this out.

I have legacies of employees with various licenses. Each legacy can have several licenses in a year.

The number of days is counted by counting the days between Date from and Date To (including the day of the Date To)

When the number of days falls in different months, I need to allocate that number of days to the respective month and be able to visualize per month the number of days per legacy.

Ex: the start date is 06/01/2021 and the end date is 05/03/2022 - the total number of days is 337.

I need to see per month the respective number of days of that license.

Thanks a lot!

Tabla Licencias.PNG

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

 

I use this table for testing.

vcgaomsft_0-1653292600732.png

You need a date table with all consecutive dates and a column as the X-axis of the year month column.

 

CALENDAR = CALENDAR(MIN('Table'[Fecha desde]),MAX('Table'[Fecha hasta]))
Month Year = FORMAT('CALENDAR'[Date],"YYYYMM")

 

No relationship needs to be created between the two tables.

vcgaomsft_2-1653292865902.png

Then create a measure.

 

Number of days by month = 
CALCULATE(
    COUNTX(
        SUMMARIZE(
            FILTER(
                CROSSJOIN('Table','CALENDAR'),
                'CALENDAR'[Date] >= 'Table'[Fecha desde]
                    && 'CALENDAR'[Date] <= 'Table'[Fecha hasta]
            ),
            'Table'[Legajo],
            'CALENDAR'[Date]
        ),
        'CALENDAR'[Date]
    )
)

 

Select a visual and drag the fields and measure into it.

vcgaomsft_1-1653292840705.png

Attach the pbix file for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

1 REPLY 1
v-cgao-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

 

I use this table for testing.

vcgaomsft_0-1653292600732.png

You need a date table with all consecutive dates and a column as the X-axis of the year month column.

 

CALENDAR = CALENDAR(MIN('Table'[Fecha desde]),MAX('Table'[Fecha hasta]))
Month Year = FORMAT('CALENDAR'[Date],"YYYYMM")

 

No relationship needs to be created between the two tables.

vcgaomsft_2-1653292865902.png

Then create a measure.

 

Number of days by month = 
CALCULATE(
    COUNTX(
        SUMMARIZE(
            FILTER(
                CROSSJOIN('Table','CALENDAR'),
                'CALENDAR'[Date] >= 'Table'[Fecha desde]
                    && 'CALENDAR'[Date] <= 'Table'[Fecha hasta]
            ),
            'Table'[Legajo],
            'CALENDAR'[Date]
        ),
        'CALENDAR'[Date]
    )
)

 

Select a visual and drag the fields and measure into it.

vcgaomsft_1-1653292840705.png

Attach the pbix file for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors