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
BIWConsult
New Member

How to calculate # of active projects with status on each day.

Hi, 

 

I'm currently working on a project where we want to plot the number of projects in a given time frame and see how many of them have which status on each day. 

 

So lets say we have:

Project IDStatusDate
Project APending01/01/2022
Project AAccepted04/01/2022
Project AExecuted05/01/2022
Project BPending03/01/2022
Project BAccepted

04/01/2022

Project CPending

04/01/2022

 

What we want to do is track how many projects have a certain status every day.

Like this:

Date# of Pending# of Accepted# of Executed
01/01/20221 (A)00
02/01/20221 (A)00
03/01/20222 (A+B)00
04/01/20221 (C)2 (A+B)0
05/01/20221 (C)1 (B)

1 (A)

 

Any ideas on how we could achieve this?

This is how we currently tried to calculate this, the problem is that the cumulative keeps going, even if the status of a project changes.

BIWConsult_2-1662305322057.png

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1662318773418.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

Hi @BIWConsult 
Actually I had a 2nd look at your request and I thought there is another option to do this which is using a mtrix visual instead of a table. You can have a disconnected table containing all unique status value and use it in the columns of the matix along with the only one measure (instead of three measures) as follows

1.png2.png

Count = 
VAR CurrentDate = 
    MAX ( 'Date'[Date] )
VAR CurrentStatus =
    SELECTEDVALUE ( 'Status'[Status] )
VAR CurrentProjects = 
    CALCULATETABLE ( 
        VALUES ( Data[Project ID] ), 
        ALL ( 'Date' ),
        'Date'[Date] <= CurrentDate 
    )
VAR SelectedProjects =
    FILTER ( 
        CurrentProjects,
        VAR CurrentData = CALCULATETABLE ( Data, ALL ( 'Date' ), 'Date'[Date] <= CurrentDate )
        VAR LastRecord = TOPN ( 1, CurrentData, Data[Date] )
        VAR LastStatus = MAXX ( LastRecord, Data[Status] )
        RETURN
            LastStatus = CurrentStatus
    )
RETURN
    COUNTROWS ( SelectedProjects )
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1662318773418.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

tamerj1
Super User
Super User

Hi @BIWConsult 

Please refer to attached sample file.

I assume you have an active relationship between your projects table and the date table which you don't have any intention to remove it.

The "CurrentProjects" is just an optimization to reduce the number of unnecessary iterations.

2.png1.png

# of Accepted = 
VAR CurrentDate = 
    MAX ( 'Date'[Date] )
VAR CurrentProjects = 
    CALCULATETABLE ( 
        VALUES ( Data[Project ID] ), 
        ALL ( 'Date' ),
        'Date'[Date] <= CurrentDate 
    )
VAR AcceptedProjects =
    FILTER ( 
        CurrentProjects,
        VAR CurrentData = CALCULATETABLE ( Data, ALL ( 'Date' ), 'Data'[Date] <= CurrentDate )
        VAR LastRecord = TOPN( 1, CurrentData, Data[Date] )
        VAR LastStatus = MAXX ( LastRecord, Data[Status] )
        RETURN
            LastStatus = "Accepted"
    )
RETURN
    COUNTROWS ( AcceptedProjects )
Greg_Deckler
Super User
Super User

@BIWConsult So why not create a Matrix visual with Date as rows, Status as Columns and a distinct count of Project ID as values?


@ 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 Greg,

 

The problem is the client wants it in a column chart like this, in order to make the evolution more visible.

BIWConsult_0-1662311967822.png

 

Kind regards

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.