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

Number of active rows by max stage reached at start of month

I have a good challenge here.

My data looks like

PersonStatus:

1.png

I have relation from Date to a Dates table (this where Month comes from).
I also have a relation between PersonStatus and a Status table (StatusID, StatusName)

 

Expected result

I want to display number of Persons whose highest StatusID reached at the start of the month:

2.png

September I have 0 since there is no data before the start of month (September 1st)

October: 1 Person has reached StatusID 10 and 20 in september (before October 1st), but I only keep the highest so it's 0 for StatusID10 and 1 for StatusID 20

November: 1 more Person reached StatusID 20 in October ((before November 1st), so total Persons = 2

December: 1 Person moved from 20 to 30 in november

 

I know how to get number of Persons for each StatusID at the start of month, it's something like:

 

 

Number Persons Start = 
VAR StartDate = MIN(Dates[Date])
VAR N = CALCULATE([Number Persons], 'Dates'[Date] < StartDate, ALL(Dates))  
RETURN N

 

 

 The part I don't get is how to include only the highest StatusID reached for each Person at the start of the month.

 

 Many Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

After few hours of trials and errors, I found the solution!

Active Persons = 
VAR StartDate = MIN ( Dates[Date] )
VAR CurrentStatus = MAX ( 'Status'[StatusID] )
RETURN
    COUNTROWS (
        FILTER (
            SUMMARIZE (
                CALCULATETABLE (
                    'Persons status',
                    'Persons status'[Date] < StartDate,
                    ALL ( Dates ),
                    ALL ( 'Status' )
                ),
                'Persons status'[PersonID],
                "StatusIDReached", MAX ( 'Persons status'[StatusID] )
            ),
            [StatusIDReached] = CurrentStatus
        )
    )

Basically,  I create a Table with all data prior to the Start of month, then Group By Person with Max(StatusID).
Then, I filter that table to keep only rows where the Highest StatusID reached equals to the variable.

It works for any Date dimension. Pretty happy about it!

View solution in original post

3 REPLIES 3
Icey
Community Support
Community Support

Hi @Anonymous ,

I have a question: For example,

for November, 1 more Person reached StatusID 20 in October ((before November 1st), so total Persons = 2.

If just for November, shouldn't the total persons be 1? So, I count all people before the month of the current row.

Is this what you want?

number.PNG

I delete the relaationship between Dates table and PersonStatus table.

PBIX file attached.

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @Icey , thanks for your reply.

 

Let's clarifiy a little bit. My intermediate table would be calculate the Max StatusID reached by Person at the start of month:

3.pngNext, I want to Count total by month from this table:

4.png

 

One person can only be counted once in every month, since they can only have one Highest Status Reached.

 

Ideally, the measure would work with any time dimension (by month, week or year).

 

 

 

Anonymous
Not applicable

After few hours of trials and errors, I found the solution!

Active Persons = 
VAR StartDate = MIN ( Dates[Date] )
VAR CurrentStatus = MAX ( 'Status'[StatusID] )
RETURN
    COUNTROWS (
        FILTER (
            SUMMARIZE (
                CALCULATETABLE (
                    'Persons status',
                    'Persons status'[Date] < StartDate,
                    ALL ( Dates ),
                    ALL ( 'Status' )
                ),
                'Persons status'[PersonID],
                "StatusIDReached", MAX ( 'Persons status'[StatusID] )
            ),
            [StatusIDReached] = CurrentStatus
        )
    )

Basically,  I create a Table with all data prior to the Start of month, then Group By Person with Max(StatusID).
Then, I filter that table to keep only rows where the Highest StatusID reached equals to the variable.

It works for any Date dimension. Pretty happy about it!

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.