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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
kylebi1
Frequent Visitor

Filter Latest Date and Value for each Row

I have a table that looks like the following:

 

NameWorkgroupActiveModified Date Time
KyleA110/7/2018
KyleA010/8/2018
KyleB010/7/2018
KyleB110/8/2018
JohnB110/7/2018
JohnB010/8/2018
JohnA010/7/2018
JohnA110/8/2018

 

I need the latest value for each [Workgroup] by [Name]

 

For example: Kyle's workgroup A was active 10/7/18, but has been de-activated on 10/8/18. 

 

Kyle's current stats for [Workgroup] A is de-activated.

 

I need to then put the sum of the activations in a table that can display how many users are active in the respective workgroup. 

 

I was able to get halfway there with a measure that filtered the max date for the active status. However, it does not work for the table. Untitled.png

7 REPLIES 7
Greg_Deckler
Super User
Super User

So, can you explain the expected results from the sample data presented and to logic to arrive at that result?



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

This is what the table looks like:

 

I need this to only show me the most current value for of ActivationFlag by filtering ActivationDateTime for each name and each workgroup.

Untitled1.png

I'm thinking something along the lines of:

 

Measure = 
VAR __Name = MAX('Table'[Name]
VAR __Workgroup = MAX('Table'[Workgroup])
VAR __ActivationDateTime = MAX('Table'[ActivationDateTime])
RETURN
MAXX(FILTER('Table',[Name]=__Name && [Workgroup]=__Workgroup && [ActivationDateTime] = __ActivationDateTime),[ActivationFlag])


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

This measure produces a blank value with no errors: 

 

measure =

VAR __Name = MAX('Workgroup Table'[Name]) VAR __Workgroup = MAX('Workgroup Table'[Workgroup])
VAR __ActivationDateTime = MAX('Workgroup Table'[ActivationDateTime])
RETURN
MAXX(FILTER('Workgroup Table',[Name]=__Name && [Workgroup]=__Workgroup && [ActivationDateTime] = __ActivationDateTime),[ActivationFlag] )

Sorry my reading comprehension was a bit poor yesterday - I missed the whole "get sum of active users" part.

 

This measure seemed to work with the test data I was using:

 

ActiveUsers = 
SUMX(
    SUMMARIZE('Workgroup Table','Workgroup Table'[Name],'Workgroup Table'[Workgroup]),
    VAR CurLastTime = CALCULATE(MAX('Workgroup Table'[ActivationDateTime])) RETURN
    CALCULATE(
        LASTNONBLANK('Workgroup Table'[ActivationFlag],1),
        'Workgroup Table'[ActivationDateTime] = CurLastTime
    )
)

 *Edit: simplified - had some unnecessary code

I think you basically have it - does it work if you use LASTNONBLANK instead of SUM in the calc?

 

CALCULATE(LASTNONBLANK(Table1[Active],Table1[Active]),FILTER(Table1,MAX(Table1[Modified Date Time])=Table1[Modified Date Time]))

Hi @Greg_Deckler

 

I need the current status for each user and their workgroup. I was able to filter for the latest modified date time for each workgroup using this measure:

 

CALCULATE(SUM(   'Workgroup Table'[ActivationFlag]), FILTER('Workgroup Table', 'Workgroup Table'[ActivationDateTime]=MAX('Workgroup Table'[ActivationDateTime])))

 

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.