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

Analysing data before and after a mileston date.

Hi, I am new here.

I have tried to look at the forums to initially solve my problem, but I am struggling to find a clear solution.

 

I have one table.

Job No.Job Start
9801 Mar 19
9901 Aug 19

 

And my fact table

 

Job No.TaskDateHours
99Support14 April 195
99Accounting26 Aug 192

 

I would like to develop a profile to analyse jobs based on months before and after [job](job start)

 

Job No.TaskMonth 1Month 2Month 3Month 4
98Set-up5 hours10 hours1510
99

Support

0023
99Accounting01055

 

In my little head - 

1. Modify [fact table](date) to month, or 1st of the month

2. Calculated column on fact table = [fact table](date) - [job](job start).

 

eg.   26th August - Modified to 01 Aug -

01 Aug - 01 Aug = Month 0

 

Is this how you would structure and solve the problem? 

Do  I create a whole new table with the new data?

If that is the right way, how do I go about it.

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

Hi @Anonymous ,

You can refer to the following steps if they are suitable for your requirements.

Steps:

1. Use 'job No' as relationship key to link two tables.

2. Create a Calendar table with whole date records.

3. Create a matrix visual with table[job No], fact[Task] as row, calendar[Year],calendar[Month] as column.

4. Write a measure to calculate based on matrix row, column and use on the above matrix visual value field.

Measure = 
VAR currdate =
    MAX ( 'Calendar'[Date] )
VAR jobstart =
    CALCULATE ( MAX ( 'Table'[Job Start] ), VALUES ( 'Table'[Job No.] ) )
VAR startDate =
    CALCULATE (
        MAX ( 'Fact'[Date] ),
        VALUES ( 'Fact'[Job No.] ),
        VALUES ( 'Fact'[Task] )
    )
VAR workhour =
    CALCULATE (
        MAX ( 'Fact'[Hours] ),
        FILTER ( ALLSELECTED ( 'Fact' ), RELATED ( 'Table'[Job Start] ) <= currdate ),
        VALUES ( 'Table'[Job No.] ),
        VALUES ( 'Fact'[Task] )
    )
VAR duartion =
    DATEDIFF (
        DATE ( YEAR ( MAX ( jobstart, startDate ) ), MONTH ( MAX ( jobstart, startDate ) ), 1 ),
        DATE ( YEAR ( currdate ), MONTH ( currdate ), 1 ),
        MONTH
    )
RETURN
    IF ( workhour <> BLANK (), workhour * duartion, 0 )

15.png

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @Anonymous ,

You can refer to the following steps if they are suitable for your requirements.

Steps:

1. Use 'job No' as relationship key to link two tables.

2. Create a Calendar table with whole date records.

3. Create a matrix visual with table[job No], fact[Task] as row, calendar[Year],calendar[Month] as column.

4. Write a measure to calculate based on matrix row, column and use on the above matrix visual value field.

Measure = 
VAR currdate =
    MAX ( 'Calendar'[Date] )
VAR jobstart =
    CALCULATE ( MAX ( 'Table'[Job Start] ), VALUES ( 'Table'[Job No.] ) )
VAR startDate =
    CALCULATE (
        MAX ( 'Fact'[Date] ),
        VALUES ( 'Fact'[Job No.] ),
        VALUES ( 'Fact'[Task] )
    )
VAR workhour =
    CALCULATE (
        MAX ( 'Fact'[Hours] ),
        FILTER ( ALLSELECTED ( 'Fact' ), RELATED ( 'Table'[Job Start] ) <= currdate ),
        VALUES ( 'Table'[Job No.] ),
        VALUES ( 'Fact'[Task] )
    )
VAR duartion =
    DATEDIFF (
        DATE ( YEAR ( MAX ( jobstart, startDate ) ), MONTH ( MAX ( jobstart, startDate ) ), 1 ),
        DATE ( YEAR ( currdate ), MONTH ( currdate ), 1 ),
        MONTH
    )
RETURN
    IF ( workhour <> BLANK (), workhour * duartion, 0 )

15.png

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

That is comprehensive!

 

On some sample data it is looking good thanks. I will give it a trial on the main info.

 

Thanks!

kentyler
Solution Sage
Solution Sage

the standard way to deal with dates in power bi is to add a "calendar" table, a dimension table for dates.

(you can find a lot of samples by googling "calendar table")

here's what your schema looks like with the calendar table added

tasks.png

the calendar table will let you filter on months without having to do date math to find start and end dates.
once you have the calendar table you can look at dax functions like PREVIOUSMONTH and find various ways of looking forwards and backwards in time.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Anonymous
Not applicable

Hi @kentyler 

 

I already have a date table, but don't understand how that will help.

The transform is dependent on start date in the job table and then translating that to month 1,2,3, so that I can compare different projects at different start times. Ie the dates month 1,2, are dynamic across each project.

 

I'm probably missing something here, and I'm more of a civilian dev rather than professional.

 

 
 

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.