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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
yazoubi
Frequent Visitor

Applying calculate with filter

Hi Dears, 

Can someone help me please to do a calculation for total staying in accommodation based on movement type (check-in/check-out) and consider the other filter like per user number  and per requester of movement type

 

- The logic will be:

         Total_Stay = (date and time for check out) - (date and time for check-in) per User, per requester, and per accommodation

 

below is an example of the data:

 

date and timeDateUserAccommodationMovement typeRequester
9/23/2021 16:129/23/2021User 1 ACC1Check-InRequester 1
9/25/2021 16:539/25/2021User 1 ACC1Check-OutRequester 1
9/23/2021 16:129/23/2021User 2ACC1Check-InRequester 3
9/25/2021 16:539/25/2021User 2ACC1Check-OutRequester 3

 

Thanks and looking forward to your support. 

 

1 ACCEPTED SOLUTION

@yazoubi , parenthesis are wrong place  , Please check my doubts

 

Datediff(
calculate(min(Table[Date Time]), allexcept(Table,Table[Requester], Table[Accommodation], Table[User]), filter(Table, Table[Movement type] ="Check-In"))
, calculate(Max(Table[DAte Time]), allexcept(Table,Table[Requester], Table[Accommodation], Table[User]), filter(Table, Table[Movement type] =" Check-Out"))
, day)

 

Or Paste the formula in text format

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@yazoubi , Try a new measure like

 


Datediff(calculate(min(Table[Date Time]), allexcept(Table,Table[Requester], Table[Accommodation], Table[User]), filter(Table, Table[Movement type] ="Check-In")),4calculate(Max(Table[DAte Time]), allexcept(Table,Table[Requester], Table[Accommodation], Table[User]), filter(Table, Table[Movement type] =" Check-Out")), day)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Dear @amitchandak ,

Thanks for your reply and note the below error, if you can assist me please

 

yazoubi_0-1632817675909.png

 

@yazoubi , parenthesis are wrong place  , Please check my doubts

 

Datediff(
calculate(min(Table[Date Time]), allexcept(Table,Table[Requester], Table[Accommodation], Table[User]), filter(Table, Table[Movement type] ="Check-In"))
, calculate(Max(Table[DAte Time]), allexcept(Table,Table[Requester], Table[Accommodation], Table[User]), filter(Table, Table[Movement type] =" Check-Out"))
, day)

 

Or Paste the formula in text format

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak ,

 

The formula in text format as below 

 

Total_Stay = DATEDIFF(CALCULATE(MIN('Accommodation Transaction'[Created date and time]),ALLEXCEPT('Accommodation Transaction','Accommodation Transaction'[Requester],'Accommodation Transaction'[Accommodation],'Accommodation Transaction'[Personnel number]), FILTER('Accommodation Transaction','Accommodation Transaction'[Movement type] ="Check-In")),calculate(Max('Accommodation Transaction'[Created date and time]), allexcept('Accommodation Transaction','Accommodation Transaction'[Requester],'Accommodation Transaction'[Accommodation],'Accommodation Transaction'[Personnel number]), filter(FILTER('Accommodation Transaction','Accommodation Transaction'[Movement type] ="Check-Out"), day)))

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.