Forum Discussion

lamacl01's avatar
lamacl01
Frequent Visitor
8 years ago
Solved

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

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

     

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

     

8 Replies

  • sdjensen's avatar
    sdjensen
    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:

    • lamacl01's avatar
      lamacl01
      Frequent Visitor

      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.

       

      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] )
              )
          )
      )
      • sdjensen's avatar
        sdjensen
        Solution Sage

        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.