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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
mihaita_baro
Helper II
Helper II

First occurence based on two filters

Hi there

 

I have a table where i store multiple appoiments for the same clients. 

 

I need to calculate something called KPI4, which means the first appoiment where AppType is 2,3 or 5 and Attendance is 5 or 6.

 

Below in green is my table and i want the output as KPI_4 in red.

 

Doesnt necesarily have to be a calculated column, can be a measure as well.

 

I've been trying all day and i can't figure out how to use Min(Appoiment) with AppType and Attendance.

 

IDAPPOINTMENTAPPTYPEATTENDANCEKPI_4
85949610/07/201723 
85949614/07/2017261
85949617/07/201723 
88847020/07/201735 
88847010/07/2017251
89149105/07/2017251
89166704/08/201735 
89166705/07/2017261
89166703/07/201732 
89166706/07/201725 
90175912/07/201735 
90175918/07/201726 
90175903/07/2017551
90787603/08/201725 
90787606/07/2017351
2 ACCEPTED SOLUTIONS
CNENFRNL
Community Champion
Community Champion

Screenshot 2021-12-08 201848.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

Hello @mihaita_baro 

 

You can create a column like this:

KPI_5 = 
VAR a =
    IF (
        COUNTX ( FILTER ( ALL ( 'Table' ), [ID] = EARLIER ( 'Table'[ID] ) ), [ID] ) >= 2,
        1
    )
RETURN
    IF (
        a = 1
            && [APPTYPE]
                IN { 2, 3, 5 }
                    && [ATTENDANCE] IN { 5, 6, BLANK () },
        1
    )

vjaneygmsft_0-1639449983148.png

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

 

View solution in original post

7 REPLIES 7
CNENFRNL
Community Champion
Community Champion

Screenshot 2021-12-08 201848.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi,

 

I am getting the folowing error message.

 

mihaita_baro_0-1639041949334.png

 

Hi, @mihaita_baro 

 

You wrote return part in the maxx function, which caused an error. 

vjaneygmsft_0-1639390279682.png

vjaneygmsft_1-1639390422349.png

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

THanks, now it worked.

I have another KPI5 to calculate which means Clients must have at least 2 appoiments where AppType is 2,3 or 5 and Attendance is 5 or 6. or blank.

 

Not sure how i can count the appoiments based on multiple filters

Hello @mihaita_baro 

 

You can create a column like this:

KPI_5 = 
VAR a =
    IF (
        COUNTX ( FILTER ( ALL ( 'Table' ), [ID] = EARLIER ( 'Table'[ID] ) ), [ID] ) >= 2,
        1
    )
RETURN
    IF (
        a = 1
            && [APPTYPE]
                IN { 2, 3, 5 }
                    && [ATTENDANCE] IN { 5, 6, BLANK () },
        1
    )

vjaneygmsft_0-1639449983148.png

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

 

parry2k
Super User
Super User

@mihaita_baro try this measure

 

First Appt = 
VAR __date =
CALCULATE ( 
    MAX ('Table'[APPOINTMENT] ), 
    TOPN ( 
        1, 
        FILTER ( ALLEXCEPT ('Table','Table'[ID] ), 'Table'[ATTENDANCE] IN { 5, 6 } && 'Table'[APPTYPE] IN { 2, 3, 5 } ),  
        MAX ('Table'[APPOINTMENT] ), 
        ASC 
    )
)
RETURN
IF ( MAX ('Table'[APPOINTMENT] ) = __date, 1 ) + 0

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



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.

Hi

 

Thanks for your help but nothing comes up, it's all blank.

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.