Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
BrandyBurk
Helper I
Helper I

Measure that will dynamically calculate status for any time period in the past based on date columns

I'm hoping someone can help me out.  I've wasted 2 days trying to get past this. I'm trying to create a measure to hold the status of my project as it is today OR as it was in the past.  Ultimately I'm trying to count the number of projects that were in each phase for any point in time.  

 

I have two tables.  One is my calendar date table called "Calendar" with 4 columns:

  • [Date]
  • [Year]
  • [Quarter]
  • [Month]  

The other table is my project data table called "Projects".  In my projects table I have the Project ID and 4 date columns that track when the project moves to various phases which are:

  • Project Approved Date (status moves from null or blank to "Planning")
  • Project Start Date (status moves from "Planning" to "In Progress")
  • Project Complete Date (status moves from "In Progress" to "Pending Review")
  • Project Closeout Date (status moves from "Pending Review" to "Complete")

As far as relationships go....[Project Approved Date] has an active relationship with my calendar table and all the rest of the date fields have an inactive relationship with my calendar table.

 

Here is the result when I put the fields in a matrix.  I've got my 'Calendar'[Year] in the column, [Project ID] in the row and the Status measure in the values well but it's not working correctly as you can see.  

 

BrandyBurk_0-1715275762556.png

Here is the DAX statement:

Status =
VAR MaxDate = MAX('Calendar'[Date])
RETURN
    IF(
        CALCULATE(MAX('Projects'[Project Closeout Date]), USERELATIONSHIP('Projects'[Project Closeout Date], 'Calendar'[Date])) <= MaxDate,
        "Complete",
        IF(
            CALCULATE(MAX('Projects'[Project Complete Date]), USERELATIONSHIP('Projects'[Project Complete Date], 'Calendar'[Date])) <= MaxDate,
            "Pending Closeout",
            IF(
                CALCULATE(MAX('Projects'[Project Start Date]), USERELATIONSHIP('Projects'[Project Start Date], 'Calendar'[Date])) <= MaxDate,
                "In Progress",
                IF(
                    MAX('Projects'[Project Approved Date]) <= MaxDate,
                    "Planning",
                    BLANK()
                )
            )
        )
    )


Here is my data:

Project IDProject Approved DateProject Start DateProject Complete DateProject Close Out Date
11/14/20201/14/20203/24/20203/24/2020
21/14/20201/14/20203/24/20203/24/2020
31/14/20201/14/20203/24/20203/24/2020
41/14/20201/14/20203/24/20203/24/2020
510/28/202010/28/20207/19/20217/19/2021
69/7/20229/7/202210/14/202210/14/2022
73/10/20233/10/20236/28/20236/28/2023
86/19/20236/19/202312/31/202312/31/2023
93/24/20233/24/20233/29/20233/29/2023
106/5/20236/5/20236/30/20236/30/2023
116/15/20236/15/2023  
1211/15/202311/15/2023  
1311/8/202311/8/202312/31/202312/21/2023
1411/16/202311/16/202312/31/202312/31/2023
156/22/20236/22/20231/31/20241/31/2024
1611/16/2023   
171/22/20241/22/2024  
1811/7/202311/7/20233/31/20243/31/2024
1911/7/202311/7/2023  
2011/7/202311/7/2023  
211/26/20241/26/2024  
2210/12/202310/12/20234/1/2024 
2310/12/202310/12/20231/31/20241/31/2024
2410/12/202310/12/202310/12/202310/12/2023
251/16/20241/16/2024  
264/11/20224/11/20224/11/20224/11/2022
278/15/20228/15/20228/15/20228/15/2022
287/31/20227/31/20227/31/20227/31/2022
299/30/20229/30/20229/30/20229/30/2022
309/30/20229/30/202212/31/202212/31/2022
3110/1/202210/1/202212/31/202212/31/2022
3212/1/202212/1/202212/31/202212/31/2022
349/30/20219/30/202110/31/202110/31/2021
359/30/20219/30/202110/31/202110/31/2021
369/1/20219/1/20219/30/20219/30/2021
379/1/20219/1/20219/30/20219/30/2021
388/1/20208/1/20201/15/20211/15/2021
3911/1/202011/1/202012/4/202012/4/2020
408/1/20208/1/20209/1/20209/1/2020
413/5/20213/5/20213/31/20213/31/2021
429/24/20219/24/20219/30/20229/30/2022
439/24/20219/24/20214/30/20224/30/2022
449/24/20219/24/20219/30/20229/30/2022
459/24/20219/24/20219/30/20229/30/2022
469/24/20219/24/202112/31/202112/31/2021
479/24/20219/24/202112/31/202112/31/2021
489/24/20219/24/202112/31/202112/31/2021
499/24/20219/24/202112/31/202112/31/2021
5012/12/202212/12/202212/31/202212/31/2022
5112/12/202212/12/202212/31/202212/31/2022
523/15/20244/25/2024  
1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @BrandyBurk ,

 

IMO, for fact tables with multiple date columns where you want to visualize the duration of the project, it is easier to perform flexible analysis if your calendar table is a disconnected table from your fact table.  

For example, I created a data model with disconnected tables like below using your data as the fact table.  

DataNinja777_0-1715520086490.png

 

Then I created measures which for the duration of the period the current status of the project will be shown like below.  Where project is approved and not completed, show letter "A" for approval.  

DataNinja777_1-1715520301717.png

If the project is started and not completed, the letter "S" is shown to indicate started.  

DataNinja777_2-1715520409934.png

If the project is completed and not closed out yet (although most of them are on the same dates), the letter "C" is shown to indicate completed.  

DataNinja777_3-1715520488932.png

If the project is closed out, "X" is shown like below:

DataNinja777_4-1715520625457.png

Then these 4 measures were combined in a text measure below, and when put in the matrix with the time dimension field in the column, you can visualize the duration of the project statuses.  

DataNinja777_6-1715520887737.png

You can further tweak the measures above to be in line with your required output.  I attach an example pbix file. 

Best regards,

View solution in original post

7 REPLIES 7
DataNinja777
Super User
Super User

Hi @BrandyBurk ,

 

IMO, for fact tables with multiple date columns where you want to visualize the duration of the project, it is easier to perform flexible analysis if your calendar table is a disconnected table from your fact table.  

For example, I created a data model with disconnected tables like below using your data as the fact table.  

DataNinja777_0-1715520086490.png

 

Then I created measures which for the duration of the period the current status of the project will be shown like below.  Where project is approved and not completed, show letter "A" for approval.  

DataNinja777_1-1715520301717.png

If the project is started and not completed, the letter "S" is shown to indicate started.  

DataNinja777_2-1715520409934.png

If the project is completed and not closed out yet (although most of them are on the same dates), the letter "C" is shown to indicate completed.  

DataNinja777_3-1715520488932.png

If the project is closed out, "X" is shown like below:

DataNinja777_4-1715520625457.png

Then these 4 measures were combined in a text measure below, and when put in the matrix with the time dimension field in the column, you can visualize the duration of the project statuses.  

DataNinja777_6-1715520887737.png

You can further tweak the measures above to be in line with your required output.  I attach an example pbix file. 

Best regards,

THANKS!!!  This is what I needed!

BrandyBurk
Helper I
Helper I

I have made progress but it's not the best scenario.  In case anyone else struggles with this, here's the solution and what the issue was.

The measure was not evaluating the status for each year independently within the context of my matrix. To ensure that the measure calculates the status correctly for each year, I had to adjust the measure to respect the filter context imposed by the matrix visual.

 

In a matrix, each cell represents a unique combination of the row and column groupings, and the calculations within each cell are subject to the filter context defined by those groupings. I had to make sure that the measure was calculating the status based on the maximum date within each respective year.  Not the best news as I like using Date Hierarchies in my visuals and this issue won't let me do that.  Will keep playing with it....if anyone has advice, would very much appreciate it!


Here's a revised version of the measure that works for an annual time period within a matrix visual and the resulting matrix screenshot.

Status = 
VAR SelectedEndDate = MAX('Calendar'[Date])
VAR CurrentYear = SELECTEDVALUE('Calendar'[Year])
VAR EndOfCurrentYear = DATE(CurrentYear, 12, 31)

VAR MaxRemediationReviewDate = CALCULATE(MAX('Event Tracking'[Remediation Review Date]), ALL('Calendar'), USERELATIONSHIP('Event Tracking'[Remediation Review Date], 'Calendar'[Date]))
VAR MaxRemediationCompleteDate = CALCULATE(MAX('Event Tracking'[Remediation Complete Date]), ALL('Calendar'), USERELATIONSHIP('Event Tracking'[Remediation Complete Date], 'Calendar'[Date]))
VAR MaxRemediationStartDate = CALCULATE(MAX('Event Tracking'[Remediation Start Date]), ALL('Calendar'), USERELATIONSHIP('Event Tracking'[Remediation Start Date], 'Calendar'[Date]))
VAR MaxDiscoveryDate = CALCULATE(MAX('Event Tracking'[Discovery Date]), ALL('Calendar')) 

VAR StatusAnnual =
    SWITCH(
        TRUE(),
        NOT(ISBLANK(MaxRemediationReviewDate)) && MaxRemediationReviewDate <= EndOfCurrentYear, "Complete",
        NOT(ISBLANK(MaxRemediationCompleteDate)) && MaxRemediationCompleteDate <= EndOfCurrentYear, "Implemented, Pending Review",
        NOT(ISBLANK(MaxRemediationStartDate)) && MaxRemediationStartDate <= EndOfCurrentYear, "In-Progress",
        NOT(ISBLANK(MaxDiscoveryDate)) && MaxDiscoveryDate <= EndOfCurrentYear, "Planning",
        BLANK() // Return a blank value if none of the conditions are met
    )

RETURN
StatusAnnual

 

BrandyBurk_0-1715371631164.png

 

BrandyBurk
Helper I
Helper I

Well I tried out SWITCH and got the EXACT same results.  Then I tried to step through the process with one status at a time and it messes up as soon as I add the next test.  I'm just flabbergasted.  Usually I can figure this stuff out after some time but I just don't see what is wrong!  Here is the SWITCH DAX below. 

Status =
VAR SelectedEndDate = MAX('Calendar'[Date])
VAR MaxRemediationReviewDate = CALCULATE(MAX('Event Tracking'[Remediation Review Date]), USERELATIONSHIP('Event Tracking'[Remediation Review Date], 'Calendar'[Date]))
VAR MaxRemediationCompleteDate = CALCULATE(MAX('Event Tracking'[Remediation Complete Date]), USERELATIONSHIP('Event Tracking'[Remediation Complete Date], 'Calendar'[Date]))
VAR MaxRemediationStartDate = CALCULATE(MAX('Event Tracking'[Remediation Start Date]), USERELATIONSHIP('Event Tracking'[Remediation Start Date], 'Calendar'[Date]))
VAR MaxDiscoveryDate = CALCULATE(MAX('Event Tracking'[Discovery Date]), USERELATIONSHIP('Event Tracking'[Discovery Date], 'Calendar'[Date]))

RETURN
SWITCH(
    TRUE(),
    MaxRemediationReviewDate <= SelectedEndDate, "Complete",
    MaxRemediationCompleteDate <= SelectedEndDate, "Implemented, Pending Review",
    MaxRemediationStartDate <= SelectedEndDate, "In Progress",
    MaxDiscoveryDate <= SelectedEndDate, "Planning",
    BLANK()
)
AndyEagleton
Frequent Visitor

What you need to do to debug this is start with one status and make sure you get that right rather than combining them all together in a single measure. Watch out for blanks. Make sure these are handled correctly.

AndyEagleton
Frequent Visitor

The DAX could be correct here though SWITCH might be better than nested IFs. The screen shot does not match the DAX. The DAX clearly has hyphen in 'In-Progress' whereas the screenshot does not.

BrandyBurk
Helper I
Helper I

Here's an example of what the correct results would be:

BrandyBurk_0-1715314658646.png

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.