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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
GOT2021
Frequent Visitor

Dax Formula Group By multiple conditions

Hi, I have this data

DateIdUserJob

10/01/2024 15:01:24

001AdamNurse
10/01/2024 15:11:24001MaxNurse
10/01/2024 16:01:24001GeorgeDoctor
15/01/2024 08:00:00002MichelNurse
17/02/2024 17:00:50003MaxNurse
1702/2024 14:10:00003GeorgeDoctor
17/02/2024 15:26:00003PatrickDoctor
25/03/2024 14:00:00004GeorgeDocor
26/03/2024 12:25:00005AnneNurse
26/03/2024 14:15:00005Sophie 


Being new to the DAX language, I must admit I'm at a loss to get the table below

I want to show this 

DateIdUserJob

10/01/2024 15:01:24

001AdamNurse
10/01/2024 16:01:24001GeorgeDoctor
15/01/2024 08:00:00002MichelNurse
17/02/2024 17:00:50003MaxNurse
17/02/2024 15:26:00003PatrickDoctor
25/03/2024 14:00:00004GeorgeDoctor
26/03/2024 14:15:00005Sophie 

 

For each ID I would like to keep at most 2 ligne :

  1. Two lines if I have "Doctor" job and one of the other jobs for the same ID.
  2. Only 1 line if :
    1. One single ID for any job (Ex : ID 002)
    2. Several lines for the same ID with either job category A (Doctor) or job category B (Nurse, NA, etc...) (but not both)

I'd thought of creating an incremental measure 1, 2,3 .... for job category B and a, b, c... for job category A so I can filter to keep only 1 and/or a but I'm  not up to that either (:

1 ACCEPTED SOLUTION
SamWiseOwl
Super User
Super User

HI @GOT2021 
Create a measure and add it into the Filter pane under Filters on this visual.

Then filter to Y.

 

Filter measure =
var curId = SELECTEDVALUE('Nurse table'[Id]) --hold current id
var curJob = SELECTEDVALUE('Nurse table'[Job]) --hold current job
var curTime = SELECTEDVALUE('Nurse table'[Date]) -- hold current date
var People = CALCULATETABLE('Nurse table',ALLSELECTED('Nurse table'), 'Nurse table'[Id] = curId) --same id people
RETURN
SWITCH(
    TRUE()
    ,COUNTROWS(People) = 1, "Y" --Keep if one person
    ,maxx(Filter(People, 'Nurse table'[Job] <> "Doctor"), [Date])= curTime && curJob <> "Doctor"
    ,"Y" --Where this row is the biggest and not a doctor
    ,(maxx(Filter(People, 'Nurse table'[Job] = "Doctor"), [Date])= curTime && curJob = "Doctor"), "Y"--you are the max doctor
    ,"N"--anything else no
)



SamWiseOwl_0-1729692921578.png

 


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

View solution in original post

3 REPLIES 3
SamWiseOwl
Super User
Super User

HI @GOT2021 
Create a measure and add it into the Filter pane under Filters on this visual.

Then filter to Y.

 

Filter measure =
var curId = SELECTEDVALUE('Nurse table'[Id]) --hold current id
var curJob = SELECTEDVALUE('Nurse table'[Job]) --hold current job
var curTime = SELECTEDVALUE('Nurse table'[Date]) -- hold current date
var People = CALCULATETABLE('Nurse table',ALLSELECTED('Nurse table'), 'Nurse table'[Id] = curId) --same id people
RETURN
SWITCH(
    TRUE()
    ,COUNTROWS(People) = 1, "Y" --Keep if one person
    ,maxx(Filter(People, 'Nurse table'[Job] <> "Doctor"), [Date])= curTime && curJob <> "Doctor"
    ,"Y" --Where this row is the biggest and not a doctor
    ,(maxx(Filter(People, 'Nurse table'[Job] = "Doctor"), [Date])= curTime && curJob = "Doctor"), "Y"--you are the max doctor
    ,"N"--anything else no
)



SamWiseOwl_0-1729692921578.png

 


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Thank you @SamWiseOwl, it's exactly what I was looking for, it answers my problem 🙂

It was a fun problem to solve.

There were other versions but this was the most efficient that I could think of!


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.