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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

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.

View solution in original post

1 REPLY 1

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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors