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
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

3 REPLIES 3
Thomas_S
Frequent Visitor

Hello

 

I was looking for a way to calculate the same values per month for my model. While searching in various topics, I found this one and it's almost what I was looking for, thank you 🙂

 

I however have an issue when I create an active relationship between my table 'calendar' et my other 'data table'. The results aren't he ones expected. How can I fix this please ? (I also have other tables in my model, which is why I need an active relationship).

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

Hi @v-cgao-msft !

 

I followed your guidelines and worked ! Now, if I want to generate a table with the columns, Legajo and the months (jan, feb ... ) with the quantity of days inside, how should I do?

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.