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! Learn more

Reply
jonnyA
Responsive Resident
Responsive Resident

Merge 2 sets of data elements then subtract

Hello,

 

I need to marry a DOS to specific Procedure Codes.  I need one measure that marries a DOS to the following Procedure Codes, 99221, 99222, 99223 (These Procedure codes represent Admit Date)

 

Then I need another measure that marries a DOS to the following Procedure Codes, 99238 and 99239 (These Procedure Codes represent the Discharge Dates)

 

Then I will need a measure that subtracts those 2 measures.

 

My goal is to find the Length of Stay of a patients stay.

 

jonnyA_0-1631107833580.png

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi  @jonnyA ,

According to the prompt error:

It is found that it is a data type problem, you can check whether [Procedure_Code] is of Text type.

vyangliumsft_0-1631670494386.png

If it is of Text type, you can modify Admit Date and Discharge Dates to the following:

Admit Date =
CALCULATE(MAX('Table'[DOS]),FILTER(ALL('Table'),'Table'[Procedure_Code] in {"99221","99222","99223"}&&'Table'[Patient_First_Name]=MAX('Table'[Patient_First_Name])))
Discharge Dates =
CALCULATE(MAX('Table'[DOS]),FILTER(ALL('Table'),'Table'[Procedure_Code] in {"99238","99239"}&&'Table'[Patient_First_Name]=MAX('Table'[Patient_First_Name])))

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

Hi  @jonnyA ,

 

This is the same as above, it is a text type, you can change the function.

{99221,99222,99223}To {"99221","99222","99223"}

{99238,99239} changed to {"99238","99239"}

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

11 REPLIES 11
jonnyA
Responsive Resident
Responsive Resident

@Anonymous , thank you so much, that worked!!!

Anonymous
Not applicable

Hi  @jonnyA ,

 

This is the same as above, it is a text type, you can change the function.

{99221,99222,99223}To {"99221","99222","99223"}

{99238,99239} changed to {"99238","99239"}

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

jonnyA
Responsive Resident
Responsive Resident

@Anonymous 

I'm having the same issue with another formula.  Have any advice on how to fix so it will work with my data??

 

jonnyA_1-1631813747413.png

 

Anonymous
Not applicable

Hi  @jonnyA ,

According to the prompt error:

It is found that it is a data type problem, you can check whether [Procedure_Code] is of Text type.

vyangliumsft_0-1631670494386.png

If it is of Text type, you can modify Admit Date and Discharge Dates to the following:

Admit Date =
CALCULATE(MAX('Table'[DOS]),FILTER(ALL('Table'),'Table'[Procedure_Code] in {"99221","99222","99223"}&&'Table'[Patient_First_Name]=MAX('Table'[Patient_First_Name])))
Discharge Dates =
CALCULATE(MAX('Table'[DOS]),FILTER(ALL('Table'),'Table'[Procedure_Code] in {"99238","99239"}&&'Table'[Patient_First_Name]=MAX('Table'[Patient_First_Name])))

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

jonnyA
Responsive Resident
Responsive Resident

@Anonymous , do you know why this fromula is not working?

 

AR From Billed Claims = SUM('New_Demo_Charge_Dataset'[Balance]) - [AR Related To Credentialing]
 
You have helped before wirth an issue similar so that is why i asm asking.  
 
Thank you in advance for your help!
 
See below for error ...

jonnyA_0-1634933314171.png

 

jonnyA
Responsive Resident
Responsive Resident

@Anonymous Thank you soooo much!!!!!!!!!!

jonnyA
Responsive Resident
Responsive Resident

@Anonymous , thank you so much for the example.  But my table goes blank when i add the measures I just created, but I dont know why?  

 

One differance I noticed from my dataset to yours is that your "Procedure Code" has the "E" in front of it, where my Procedure Code does not.  Not sure if that is the issue or not.

Anonymous
Not applicable

Hi  @jonnyA ,

I created some data:

vyangliumsft_0-1631586078279.png

Here are the steps you can follow:

Find the Length of Stay of a patients stay

1. Create measure.

Admit Date =
CALCULATE(MAX('Table'[DOS]),FILTER(ALL('Table'),'Table'[Procedure_Code] in {99221,99222,99223}&&'Table'[Patient_First_Name]=MAX('Table'[Patient_First_Name])))
Discharge Dates =
CALCULATE(MAX('Table'[DOS]),FILTER(ALL('Table'),'Table'[Procedure_Code] in {99238,99239}&&'Table'[Patient_First_Name]=MAX('Table'[Patient_First_Name])))
Length of Stay of a patients stay=
DATEDIFF([Admit Date],[Discharge Dates],DAY)

2. Result:

vyangliumsft_1-1631586078285.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

jonnyA
Responsive Resident
Responsive Resident

@Anonymous I want to show you the errors that I am getting ... 

 

Admit Date Measure 

jonnyA_0-1631635095007.png

 

Discharge Date Measure

jonnyA_1-1631635256581.png

 

Length of Stay of a Patients Stay 

jonnyA_2-1631635328394.png

 

amitchandak
Super User
Super User

@jonnyA , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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

@amitchandak 

jonnyA_0-1631120387065.png

I'm not sure if this will help or not, but here is a small sample size of data.  

 

Do you know how to create a measure that will only pull Procedure Codes 99221, 99222 and 99223?

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.

Top Solution Authors