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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Kryne7
New Member

Measure to Count Entries Using Latest Date Compared to a Dynamic Date

I'm pretty sure that some combination of VAR, CalculateTable, Summarize, or the like can get me a measure of what I'm wanting but I'm not having any luck.  I'm going to include sample data to hopefully explain the situation more clearly.

 

First, I have a table with survey data (Survey_Answers).  Each row is a single answer from a single employee but each employee will be answering the survey multiple times a year, as it goes out monthly.  Below, I have three columns where Employee_ID is the unique ID per employee, Round_End is when the specific survey round ended, and eNPS_Type that is either "Promoter", "Passive" or "Detractor."

 

Employee_IDRound_EndeNPS_Type

00001

1/19/2025Promoter
000012/16/2025Promoter
000013/16/2025Promoter
000021/19/2025Passive
000022/16/2025Detractor
000023/16/2025Passive
000031/19/2025Promoter
000032/16/2025Promoter
000042/16/2025Detractor
000043/16/2025Promoter

 

The way the calculation needs to work, is that on a line graph (or using a slicer that the user can pick from) each Round_End date needs to count the distinct count of Employee_ID of Promoters, Passives, and Detractors but using the latest date before or equal to the selected Round_End Date.

 

So below is what I would expect the "calculated table" for each of these months to look like and the subsequent count of each of the three categories.

January

Employee_IDRound_EndeNPS_Type

00001

1/19/2025Promoter
000021/19/2025Passive
000031/19/2025Promoter

Promoters - 2, Passives - 1, Detractor - 0

 

February

Employee_IDRound_EndeNPS_Type
000012/16/2025Promoter
000022/16/2025Detractor
000032/16/2025Promoter
000042/16/2025Detractor

Promoters - 2, Passives - 0, Detractors - 2

 

March

Employee_IDRound_EndeNPS_Type
000013/16/2025Promoter
000023/16/2025Passive
000032/16/2025Promoter
000043/16/2025Promoter

Promoters - 3, Passive - 1, Detractor - 0

 

I highlighted the answer from Employee_ID 00003 in the third example because I feel that this is where the complication comes in.  This specific employee didn't take the survey in March, so the count needs to include that person's "latest" answer which was the 2/16 response.

 

I have a dimension table with a column of just the dates of the Round_End but I'm not sure if that is needed.  

 

In the end, I'd like a measure to give me the total count of entries that meet these requirements, and then a measure for counts for each of the three categories.

 

As an added bonus, there is one more wrinkle but it might not be a big deal after I figure this out, but I'll throw it here too.  In the first Survey_Answers table, there is a Termination_Date column for any employees who have taken the survey but were then terminated.  We want to include their entries for 3 months from their termination date and then filter them out after that.  I created an Inclusion_Date column that just moves the termination date forward 12 weeks, which then gives the date that after, we don't want to include their survey answers anymore.  I'm not sure if this part can be built into the measure I'm asking about up above or if this needs to be a seperate thing.

 

Any help is greatly appreciated!  Thank you.

 

Kristofer

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Kryne7 try following measure, use round_end date from the dimension table you have created, make sure that table doesn't have relationship with the main table:

 

Top = 
VAR __SelectedDate = SELECTEDVALUE ( Round_End[Round_End] )

VAR __Return = 
CALCULATE ( 
    COUNTROWS ( 'Table1' ),
    INDEX (
            1,
            SUMMARIZE ( FILTER ( ALL ( Table1 ), Table1[Round_End] <= __SelectedDate ), Table1[Employee_ID], Table1[Round_End]),
            ORDERBY ( Table1[Round_End], DESC ),
            PARTITIONBY ( Table1[Employee_ID] )
            
        )
)
RETURN __Return 

 

parry2k_0-1741901661939.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@Kryne7 I have couple of videos on my YT channel on INDEX function:

 

Let's explore INDEX function in Power BI and learn how it is different from other WINDOW functions

Learn how easy to get top sales by each category using INDEX WINDOW function in Power BI

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Kryne7 try following measure, use round_end date from the dimension table you have created, make sure that table doesn't have relationship with the main table:

 

Top = 
VAR __SelectedDate = SELECTEDVALUE ( Round_End[Round_End] )

VAR __Return = 
CALCULATE ( 
    COUNTROWS ( 'Table1' ),
    INDEX (
            1,
            SUMMARIZE ( FILTER ( ALL ( Table1 ), Table1[Round_End] <= __SelectedDate ), Table1[Employee_ID], Table1[Round_End]),
            ORDERBY ( Table1[Round_End], DESC ),
            PARTITIONBY ( Table1[Employee_ID] )
            
        )
)
RETURN __Return 

 

parry2k_0-1741901661939.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thank you!  That worked perfectly.

 

I've never used the Index function but thanks to your solution, I think I've learned about a new tool for the tool set.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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