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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anwar
Frequent Visitor

Create new columns with latest values based on a type from a related table

I have a Dim table that represents patients and a Fact table with 4 million records that represents Blood Results.
The Blood Results table has the following columns:

  • PatientId
  • Date
  • Type
  • Value

The relationship is 1-to-many and the PatientId column is the key.
There are 3 types of Blood Tests that I want to display on the Patient table:

  • ALT
  • HBV DNA
  • HbeAg

I want to get the latest Result for the above 3 types and show them on 3 separate columns.

 

Here is a small sample of the Blood Results table for six patients and their blood work:

PatientIdDateTypeResultValue
11/01/2019ALT10
125/01/2019ALT10.1
114/01/2019HBV DNA10.5
115/03/2019HbeAg10.66
129/12/2019BIL10.49
231/01/2019ALT2.2
23/11/2019HBV DNA3.9
229/07/2019HBV DNA2.3
315/06/2019HbeAg3.3
412/06/2019BIL4.1
417/06/2019BIL4.2
422/09/2019ALT4.9
48/04/2019HbeAg3.99
411/11/2019HbeAg4.61
419/06/2019ALT5.01
530/06/2019ALT5.6
625/01/2019HBV DNA0

 

This is the expected output

PatientIdLatest ALTLatest HBV DNALatest HbeAg
110.110.510.66
22.22.3 
3  3.3
44.9 4.61
55.6  
6 0 

 

I'm looking for a DAX expression that creates three column in green color as in the table above.

1 ACCEPTED SOLUTION
MattAllington
Community Champion
Community Champion

You should be able to write a single measure and then use the column “type” you have as the column in the matrix. Something like this will work I think (not tested)

 

=CALCULATE(SELECTEDVALUE(FACT[value]),LASTDATE(fact[date]))



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

1 REPLY 1
MattAllington
Community Champion
Community Champion

You should be able to write a single measure and then use the column “type” you have as the column in the matrix. Something like this will work I think (not tested)

 

=CALCULATE(SELECTEDVALUE(FACT[value]),LASTDATE(fact[date]))



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.