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
lamacl01
Frequent Visitor

Project status duration

Hi all,

 

I would use some help with query related to projects overview. I have a list of projects IDs (Items), their status (Status) and date when project's status has been updated (Update Date). Each update is in a separate row.

 

ItemsStatusUpdate Date
1A14/05/2018
1B14/06/2018
1C17/07/2018
1D12/09/2018
1E01/12/2018
1F01/03/2019
1G01/06/2019
2A14/01/2018
2B14/02/2018
2C14/03/2018
2D14/04/2018
2E14/05/2018
2F14/06/2018
2G14/07/2018
3A20/01/2017
3B20/03/2017
3C20/05/2017
3D20/07/2017
3E20/09/2017

 

What I need it so create a table where every project 's status will have reflected month or months when this status was current. Like in table here

ItemMonthStatus
1Jan-18 
1Feb-18 
1Mar-18 
1Apr-18 
1May-18A
1Jun-18B
1Jul-18C
1Aug-18C
1Sep-18D
1Oct-18D
1Nov-18D
1Dec-18E
1Jan-19E
1Feb-19E
1Mar-19F
1Apr-19F
1May-19F
1Jun-19G
1Jul-19 
1Aug-19 

 

So I would be able to identify how many months each status of project lasted.

 

Is there anyone who can help me with this?

 

Many thanks

 

Lukas

1 ACCEPTED SOLUTION

Hi @lamacl01,

 

You get a wrong result because your values in the Status column will not return the correct result if you pick the maximum value, so we need to add some kind of statusID column, that can be used to sort the status's in the correct order.

 

As you can see in the screenshot below, I have added a Status table that also includes a statusId column. I have also calculated a new statusID column in my Table1 that I will need for the calculation. It's important that the relationship between the tables is set to 'Table1'[Status] --> 'Status'[Status] and not between the ID columns, hence you need to the relationship to calculate the statusID in Table1

 

I have calculated the 'Table1'[StatusID] with this formula: (edit: wrote Status instead of StatusID)

StatusID = 
CALCULATE(
    VALUES( 'Status'[StatusID] );
    Table1[Status] = RELATED( 'Status'[Status] )
)

 

Then we need to change the formula for the "Status (MonthEnd)" Measure and first calculate the Maximun StatusID used on an item by the end of a given month and then use this value to calculate the Status that you want to see. My final measure looks like this now:

Status (MonthEnd) = 
VAR MaxUpdateDate = CALCULATE( MAX( Table1[Update Date] ); ALL( Period ) )
VAR MaxStatusId =
IF( 
    MIN( Period[Date] ) <= MaxUpdateDate;
    CALCULATE(
        MAX( Table1[StatusID] );
        FILTER(
            ALL( Period );
            Period[Date] <= MAX( Period[Date] )
        )
    )
)
RETURN
CALCULATE(
    VALUES( 'Status'[Status] );
    MaxStatusId = 'Status'[StatusID] 
)

 

And this is the result I get with your data:

ProjectStatusDuration2.png

 

Edit: I noticed something with your relationship to your calendar table - you have set Cross Filter Direction to "Both" - this should always be single unless you really need "Both".

 

/sdjensen

View solution in original post

8 REPLIES 8
sdjensen
Solution Sage
Solution Sage

Hi @lamacl01,

 

You could try with this DAX measure:

Status (MonthEnd) = 
VAR MaxUpdateDate = CALCULATE( MAX( Table1[Update Date] ); ALL( Period ) )

RETURN
IF( 
    MIN( Period[Date] ) <= MaxUpdateDate;
    CALCULATE(
        MAX( Table1[Status] );
        FILTER(
            ALL( Period );
            Period[Date] <= MAX( Period[Date] )
        )
    )
)

 

Besides your data for illustration I have added a calendar table (called period) and a table with all the items to my model and created a relationship between the tables.

 

From the above I can get this result:

ProjectStatusDuration.png

/sdjensen

@sdjensen Hi,

 

many thanks for your help. Unfortunatelly I wasn't able to use this function correctly for my data. Whould you be able to double check your formula? In attached screen there is a result I am receiving. If you compare right table with source data and results on the left table, there is something wrong.project overview.PNG

 

my function:

 

Status (MonthEnd) = 
VAR MaxUpdateDate = CALCULATE( MAX( Sheet1[Date of change] ), ALL( 'Calendar' ) )

RETURN
IF( 
    MIN( 'Calendar'[Date] ) <= MaxUpdateDate,
    CALCULATE(
        MAX( Sheet1[Attribute.1] ),
        FILTER(
            ALL( 'Calendar'),
            'Calendar'[Date] <= MAX( 'Calendar'[Date] )
        )
    )
)

Hi @lamacl01,

 

Your formula seems okay.

 

Can you verify that your Calendar table includes ALL dates from the first day of the year of your lowest date in [Date of Change] to the last day of the year of the maximum date in [Date of Change] ?

 

Can you verify that you have created a relationship between your Sheet1 table and your calendar table?

 

I noticed that the ID column in Sheet1 seems to be formated as a number, hence when adding it to visuals PBI will by default think this is a number to an summarized, which would never be the case. It should not affect the result of your formula, but you should format it as a text in the Query Editor.

/sdjensen

Hi @sdjensen,

 

I have checked everything you are mentioning, I have a calendar table dated from 01/01/2016 and there is also connection between calendar and date. I have also changed data type of Id to Text.

Capture 2.PNG

Hovewer still my results are not the ones I would like to get.

If you have a look at left table results for ID 10. There are only four rows with months, but I would like to get a full lifetime of project overview something like this

 

Capture4.PNG

 


 Capture3.PNG

Is this something you would be able to help me with?

 

Regards.

 

Lukas

 

 

Hi @sdjensen,

 

 

I have tried your suggestion and created a column StatusID in my source file using "StatusID" column in my REF table.

StatusID =
CALCULATE (
    VALUES ( 'REF table'[StatusID] ),
    Sheet1[Attribute.1] = RELATED ( 'REF table'[Status] )
)

which I have used for measure Status (MonthEnsd)

Status (MonthEnsd) = 
VAR MaxUpdateDate =
    CALCULATE ( MAX ( Sheet1[Date of change] ), ALL ('Calendar') )
VAR MaxStatusId =
    IF (
        MIN ( 'Calendar'[Date] ) <= MaxUpdateDate,
        CALCULATE (
            MAX ( Sheet1[StatusID] ),
            FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] <= MAX ( 'Calendar'[Date] ) )
        )
    )
RETURN
    CALCULATE ( VALUES ( Sheet1[StatusID] ), MaxStatusId = Sheet1[StatusID] )

there is a conection between my REF table and source table with status description

Capture.PNG

 

unfortunatelly I am still not receiving correct output.

Capture2.PNG

 

Whould you know what might be a problem here?

 

Many thanks

Regards.

 

Lukas

Hi @lamacl01,

 

I had a look at your file.

 

You have to Status' with the same value in StatusID in the Status table. This is causing your problem with the formula not working.

 

Also you should add a column in your Calendar table to sort your "Month & Year" column. I created a calculated column with the following DAX (remember to set the column to data type: Whole Number)

YearMonthSort = YEAR('Calendar'[Date]) & RIGHT("0" & MONTH('Calendar'[Date]); 2)

Then select your "Month & Year" Column and on the Modeling Tab you select "Sort by Column" and then your new calculated column.

 

/sdjensen

Hi @lamacl01,

 

It's strange that it's working in my model, but not yours. Did you change the relationship to your date table as I described in my last post?

 

Would you be able to share your .pbix file with me, so I can have a look at it? If you don't want to share it to the public, you can send me a PM with a download link to it.

/sdjensen

Hi @lamacl01,

 

You get a wrong result because your values in the Status column will not return the correct result if you pick the maximum value, so we need to add some kind of statusID column, that can be used to sort the status's in the correct order.

 

As you can see in the screenshot below, I have added a Status table that also includes a statusId column. I have also calculated a new statusID column in my Table1 that I will need for the calculation. It's important that the relationship between the tables is set to 'Table1'[Status] --> 'Status'[Status] and not between the ID columns, hence you need to the relationship to calculate the statusID in Table1

 

I have calculated the 'Table1'[StatusID] with this formula: (edit: wrote Status instead of StatusID)

StatusID = 
CALCULATE(
    VALUES( 'Status'[StatusID] );
    Table1[Status] = RELATED( 'Status'[Status] )
)

 

Then we need to change the formula for the "Status (MonthEnd)" Measure and first calculate the Maximun StatusID used on an item by the end of a given month and then use this value to calculate the Status that you want to see. My final measure looks like this now:

Status (MonthEnd) = 
VAR MaxUpdateDate = CALCULATE( MAX( Table1[Update Date] ); ALL( Period ) )
VAR MaxStatusId =
IF( 
    MIN( Period[Date] ) <= MaxUpdateDate;
    CALCULATE(
        MAX( Table1[StatusID] );
        FILTER(
            ALL( Period );
            Period[Date] <= MAX( Period[Date] )
        )
    )
)
RETURN
CALCULATE(
    VALUES( 'Status'[Status] );
    MaxStatusId = 'Status'[StatusID] 
)

 

And this is the result I get with your data:

ProjectStatusDuration2.png

 

Edit: I noticed something with your relationship to your calendar table - you have set Cross Filter Direction to "Both" - this should always be single unless you really need "Both".

 

/sdjensen

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.