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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
EF
Helper II
Helper II

fill in blank values from most recent row for specific ID

Hi all,

 

I have been searching this for a while.

I need to fill in missing data based on rows before for the specific ID.

The rows are records of events for each patient (admit date, appointments, discharge...)

Depending on the event, sometimes alot of other data is missing.

For example, every appointment row has the patients' current diagnosis at the time of the appointment. However, discharge events have no diagnosis associated. I want to fill the empty diagnosis with the patients most recent diagnosis.

 

I tried : 

 

IF (
Combined_Queries[DiagnosisKey1] = BLANK (),
CALCULATE (
LASTNONBLANK ( Combined_Queries[DiagnosisKey1], Combined_Queries[DiagnosisKey1] ),
FILTER(ALLEXCEPT ( Combined_Queries, Combined_Queries[account] ),Combined_Queries[date]<=earlier(Combined_Queries[date]))),
 
Combined_Queries[DiagnosisKey1]
)
 
Combined_Queries is the name of the table, DiagnosisKey1 is the column missing values, account is the ID for each patient, date is date of the event.
 
This fills in the first blank correctly, but every other blank gets filled with that same value. I need it to change based on the most recent event for that date.
 
Query Editor fill down doesn't help either because it fills down regardless of the account number.
 
Any ideas?
 

 

1 ACCEPTED SOLUTION
JarroVGIT
Resident Rockstar
Resident Rockstar

Hi @EF ,

Well, how can PBI know which DiagnosticKey1 needs to be used then if the Account and Date can be the same? So let's say someone (Account A)has an appointment on Jan 1st for the Flu and later that day for the Cold. Then, on Jan 2, the DiagnosticKey1 is empty. What would the fill be, Flu or Cold?

If it doesn't matter, you can use the following as a calculated column:

FilledDiagnosisKey = 
IF(Combined_Queries[DiagnosisKey1] = BLANK(),
    VAR _curAccount = Combined_Queries[Account]
    VAR _curDate = Combined_Queries[Date]
    VAR _filteredTable = FILTER(Combined_Queries, Combined_Queries[Account] = _curAccount && Combined_Queries[DiagnosisKey1] <> BLANK() && Combined_Queries[Date] < _curDate)
    VAR _maxDate = MAXX(_filteredTable, Combined_Queries[Date])
    RETURN
    MAXX(FILTER(_filteredTable, [Date] = _maxDate && [Account] = _curAccount), [DiagnosisKey1])
, Combined_Queries[DiagnosisKey1])

In my original test table, I added a row for Jan 1st, Account A with DiagnosticKey1 = Sick. The result is this:

image.png

Let me know if this helps you. Don't forget to give kudo's for support 🙂

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

7 REPLIES 7
JarroVGIT
Resident Rockstar
Resident Rockstar

Hi @EF 

I started with this table:

 image.png

Then I used the following calculated column (this is not optimized but it is easier to read and understand the logic):

FilledDiagnosisKey = 
IF(Combined_Queries[DiagnosisKey1] = BLANK(),
    VAR _curAccount = Combined_Queries[Account]
    VAR _curDate = Combined_Queries[Date]
    VAR _filteredTable = FILTER(Combined_Queries, Combined_Queries[Account] = _curAccount && Combined_Queries[DiagnosisKey1] <> BLANK() && Combined_Queries[Date] < _curDate)
    VAR _maxDate = MAXX(_filteredTable, Combined_Queries[Date])
    RETURN
    LOOKUPVALUE(Combined_Queries[DiagnosisKey1], Combined_Queries[Account] , _curAccount, Combined_Queries[Date] , _maxDate),
    Combined_Queries[DiagnosisKey1])

Result is:

image.png

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks @JarroVGIT  for your quick response!

 

I got this error message: A table of multiple values was supplied where a single value was expected.

JarroVGIT
Resident Rockstar
Resident Rockstar

You are adding a measure, but this dax needs to be a calculated column. A very important difference 🙂 You should get any errors if applying the DAX as a calculated column.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@JarroVGIT Hi I just got back on my computer...

I used a calculated column, still got that error message:

'A table of multiple values was supplied where a single value was expected.'

Maybe that error is because it is possible for a client to have more than 1 entry for a single date? The entries are appointments and they can have multiple appointments per day (for different services)

JarroVGIT
Resident Rockstar
Resident Rockstar

Hi @EF ,

Well, how can PBI know which DiagnosticKey1 needs to be used then if the Account and Date can be the same? So let's say someone (Account A)has an appointment on Jan 1st for the Flu and later that day for the Cold. Then, on Jan 2, the DiagnosticKey1 is empty. What would the fill be, Flu or Cold?

If it doesn't matter, you can use the following as a calculated column:

FilledDiagnosisKey = 
IF(Combined_Queries[DiagnosisKey1] = BLANK(),
    VAR _curAccount = Combined_Queries[Account]
    VAR _curDate = Combined_Queries[Date]
    VAR _filteredTable = FILTER(Combined_Queries, Combined_Queries[Account] = _curAccount && Combined_Queries[DiagnosisKey1] <> BLANK() && Combined_Queries[Date] < _curDate)
    VAR _maxDate = MAXX(_filteredTable, Combined_Queries[Date])
    RETURN
    MAXX(FILTER(_filteredTable, [Date] = _maxDate && [Account] = _curAccount), [DiagnosisKey1])
, Combined_Queries[DiagnosisKey1])

In my original test table, I added a row for Jan 1st, Account A with DiagnosticKey1 = Sick. The result is this:

image.png

Let me know if this helps you. Don't forget to give kudo's for support 🙂

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




It works! Thanks so much! Useful for so many things. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.