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
gselvag
Helper I
Helper I

DAX with calculation between start and finish dates

Hi,

 

I need a expert advice on how to create a calculated column or measure. The challange I have is with following table.

 

Table 1 (fact table):

Name (Text type)

StartDate (Date/Time type)

FinishDate (Date/Time type)

Project (Text type)

Type (Text type)  example - budget, actual, forecast

 

Table 2 (calendar table):

Date

Month

Quarter

 

 

I need to figure out how to calculate number of days for each month that fall in between start - finish date.

Am thinking about measure, but maybe it's not the right way since I need to visualize (budget, actual) by month in a table and combination chart. Please, give me some help to get started on the right way.

 

Thanks for any advice.

 

1 ACCEPTED SOLUTION

Hi @gselvag,

 

First, create a calendar table to list unique continual dates.

Calendar date = CALENDAR(MIN('Fact Table'[StartDate]),MAX('Fact Table'[FinishDate]))

Then, create a calculated table via cross join FACT table and above calendar table. And add a calculated column.

Cross Join =
FILTER (
    CROSSJOIN ( 'Fact Table', 'Calendar date' ),
    [Date] >= 'Fact Table'[StartDate]
        && [Date] < 'Fact Table'[FinishDate]
)

Month Name = 'Cross Join'[Date].[Month]

2.PNG

 

Use a Matrix visual to display data records from above table.

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

7 REPLIES 7
gselvag
Helper I
Helper I

Hi Power BI,

I need your help folks!

 

Have SharePoint List (Task) that I need to calculate number of days based on Start and Finish date, grouped by Type (Actual, Budget and Forecast) and period (Month / Week). Here's some sample data.

 

SCHEDULE (FACT TABLE):

TaskName  |  StartDate  |   FinishDate   |    Resource   |    Type        |   IsActual   |  ExcIude

Task01          01.01.2018     30.05.2018         RES-01          Budget         False         True

Task02          10.02.2018     15.03.2018         RES-02          Budget         False         True

Task03          01.06.2018     01.07.2018         RES-01          Budget         False         True

Task04          16.03.2018     20.06.2018         RES-02          Budget         False         True

Task20          01.01.2018     15.01.2018         RES-01          Actual          True           False

Task21          20.02.2018     25.03.2018         RES-01          Forecast       False          False

Task22          01.06.2018     01.07.2018         RES-02          Actual          True           False

Task23          02.07.2018     15.07.2018         RES-02          Forecast       False          False

Task23          10.06.2018     10.07.2018         RES-02          Forecast       False          True

 

 

The Exclude field checked TRUE and intended to avoid it in the Calculation as it's overlapping tasks (resource only allow one task either Actual or Forecast in date span).

 

1. Need to CALCULATE number of days (duration) by month (e.g. to be used in Combinations Chart / Pivot Table).

 

2. Need to CALCULATE number of days by month, divided by actual and forecast. Formula with a parametre/variable to set the current month.

 

Waiting for your assistance for this issue, Thanks!

Greg_Deckler
Super User
Super User

I'm thinking that measures are probably the way to go. Otherwise, you would need a column in your calendar table for each project or a column in your projects table for each month (wouldn't be tragic). Any way you can post sample data so that we can play around with a solution?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi,

 

Have you been able to consider a solution for what am looking to acheive. Appreciate any tips - am currently going nowhere.

 

Thanks, Geir

Thank you for your feedback!

 

Here are some sample data in data model. Possible it needs more columns to make the report with measures possible. The datasource is a SharePoint Task list that is syncronized with MS Project. The project plan table is cleaned with only relevant tasks (summary items excluded). Here's some sample data.

 

FACT TABLE 1: SharePoint Task list with Budget items

TaskName  |  StartDate  |   FinishDate   |    Resource   |    Type

Task01          01.01.2018     30.05.2018         RES-01          Budget

Task02          10.02.2018     15.03.2018         RES-02          Budget

Task03          01.06.2018     01.07.2018         RES-01          Budget

Task04          16.03.2018     20.06.2018         RES-02          Budget

 

FACT TABLE 2: SharePoint Task list with Actual / Forecast items

TaskName  |  StartDate  |   FinishDate   |    Resource   |    Type        |   IsActual   |  ExcIude

Task20          01.01.2018     15.01.2018         RES-01          Actual          True           False

Task21          20.02.2018     25.03.2018         RES-01          Forecast       False          False

Task22          01.06.2018     01.07.2018         RES-02          Actual          True           False

Task23          02.07.2018     15.07.2018         RES-02          Forecast       False          False

Task23          10.06.2018     10.07.2018         RES-02          Forecast       False          True

 

The Exclude field checked TRUE and intended to avoid miscalculation of overlapping tasks (since resource only allow one task in actual/forecast date span). Maybe not best solution, but team want to review forecast to select best fit. The IsActual field is checked TRUE when 'FACT TABLE 2'Task20 is completed as actual.

 

1. Need to report, calculate Days durations to be visualized by month (e.g. to be used in combinations chart / crosstab / pivot / table). Slice by Resource and Measures for Budget / Actual / Forecast Type. 

 

2. Need to create another report with actual + forecast, depending what current reporting month so that combination chart / crosstab plot actual (e.g. January) and forecast for remaining months.

 

Highly appreciate the help, and need to learn more how Power BI, DAX can resolve the issue.

 

 

Hi @gselvag,

 

First, create a calendar table to list unique continual dates.

Calendar date = CALENDAR(MIN('Fact Table'[StartDate]),MAX('Fact Table'[FinishDate]))

Then, create a calculated table via cross join FACT table and above calendar table. And add a calculated column.

Cross Join =
FILTER (
    CROSSJOIN ( 'Fact Table', 'Calendar date' ),
    [Date] >= 'Fact Table'[StartDate]
        && [Date] < 'Fact Table'[FinishDate]
)

Month Name = 'Cross Join'[Date].[Month]

2.PNG

 

Use a Matrix visual to display data records from above table.

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you very much for your solution. Does this enable me to calculate days as decimal? I looking to find a way to calculate days with decimals (include time) for each month. Is it the datatype or do I need to crossjoin with a data time table? I hope not. Thanks.

gselvag
Helper I
Helper I

Have a challange with calculate days between dates and visualize them by month (timephased).

The data will be based on two tables (no relationship)

 

1. SCHEDULE TABLE
    Table: Tasks
    Fields: Task Name, Start Date, Finish Date, Project

2. CALENDAR TABLE
    Table: Calendar
    Fields: Date, Month, Week

 

My question is how can I utilize a measure formula to visualize number of days, timephased (split by e.g. month and week) by project. We need a pivot like report (crosstab) with dataset to use in combination chart where days are summarized by month (columns).

 

Any tip on how to resolve this would help a lot.

 

Thanks

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.