cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ashwini12
Microsoft
Microsoft

Hi All, I want to count the latest dates before slicer selected date dynamically with table filters.

Aim : To count previous open ticket - We want to count all distinct ticket ID having dates before slicer selected date (such that we only take the latest Auditcreated date of Ticket ID before slicerselected date) with below filters

Status column - should not be closed or removed
IsActive column should be - true
AuditCreatedDate - should be before slicer selected date
CreatedDate -    should be before slicer selected date

 

IMP : We should only consider latest AuditCreatedDate "before slicer selected date". 

Note: I have created measure for date before slicer selected date as

End Of Previous Period = [FirstSelectedDate] - 1 and start date is static as
Start Of Previous Period = DATE(2021, 1, 1)
So we should consider all the dates between  [Start Of Previous Period] and [End Of Previous Period].
 

Explanation:

Consider below 1st scenario:

slicer - 13 june to 12 july


ID  AuditCreatedDate  Status    IsActive
1     12 June                 open        True ----- max(+1)
1     11 June                 close        True
1     10 June                 close        True
2     11 June                 open        True ----- max (+1)
2     10 June                 open        True
2      9 June                   close       True
3      7 June                   close       False
3      6 June                   open       True


Ans: Previous Open ticket count = 2
------------------------------------------------------------------------------------------

Consider below 2nd scenario:

slicer - 12 june to 12 july


ID  AuditCreatedDate Status IsActive
1     12 June                 open    True  {should not consider this record as AuditedCreatedDate should be before 12 June }
1     11 June                 open     True ---- max (+1)
1     10 June                 close     True
2     11 June                 close     True         {should not consider this record as status is close}
2      10 June                open     True
2      9 June                  close     False
3      13June                 open     True {should not consider this record as AuditedCreatedDate should be before 12 June }

3      10 June                open     True -- ---max(+1)
3      6 June                  open     False


Ans: Previous Open ticket count = 2

[Previous Open Tickets] =
CALCULATE(DISTINCTCOUNT('View_AllHelpToolRequestsWithAudit (2)'[Id]),
'View_AllHelpToolRequestsWithAudit (2)'[AuditNewStatusId] <> 3 || 'View_AllHelpToolRequestsWithAudit (2)'[AuditNewStatusId] <> 4 ,
'View_AllHelpToolRequestsWithAudit (2)'[AuditIsActive] = TRUE(),
DATESBETWEEN(
('View_AllHelpToolRequestsWithAudit (2)'[AuditCreatedDate]),[Start Of Previous Period],[End Of Previous Period]),
DATESBETWEEN((Dim_Date[Date]),[Start Of Previous Period],[End Of Previous Period])
)
We have to give latest AuditCreated date between these two date ranges.
2 REPLIES 2
amitchandak
Super User
Super User

@ashwini12 , Try a measure like


measure =
var _max = maxx(filter(allselected(Table), [ID] = max(Table[ID])), [AuditCreatedDate])
var _1 = maxx(allselected(Date), Date[Date])
return
countx(filter(values(Table[ID]),_max <= _1), [ID])

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!

@amitchandak The solution provided by you gives maximum date in the entire table, requirement is different.
In the below measure we want to give only latest AuditCreated dates per ID between date range [Start Of Previous Period] and [End Of Previous Period].

Previous Open Tickets] =
CALCULATE(DISTINCTCOUNT('View_AllHelpToolRequestsWithAudit (2)'[Id]),
'View_AllHelpToolRequestsWithAudit (2)'[AuditNewStatusId] <> 3 || 'View_AllHelpToolRequestsWithAudit (2)'[AuditNewStatusId] <> 4 ,
'View_AllHelpToolRequestsWithAudit (2)'[AuditIsActive] = TRUE(),
DATESBETWEEN(
('View_AllHelpToolRequestsWithAudit (2)'[AuditCreatedDate]),[Start Of Previous Period],[End Of Previous Period]),
DATESBETWEEN((Dim_Date[Date]),[Start Of Previous Period],[End Of Previous Period])
)

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May 23 2022 episode 5 with aka link.jpg

The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt will talk about the importance of Data Modeling.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!