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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
rgalvez
Frequent Visitor

DAX for earliest value

Hello experts!
My dataset is built of three tables: Users, Mastery and Exams.

The Users table is the link (one-to-many relation) between Mastery and Exams tables, as follows:

rgalvez_0-1690221973303.png

 

The expected outcome is a new table that includes all the fields from the Exams table and a new column with the Mastery value for the initial date [Initial Date Mastery], for that user, for that moduleID (taken from the Mastery[Initial Date Mastery]), and another column with the Mastery value for the final date [Final Date Mastery], for that user and for that moduleID (taken from the Mastery[Final Date Mastery]).

 

This is how the outcome should look:

rgalvez_1-1690221973314.png

 

If you follow the colors, the green fields are from the Exams table, and the orange values are from the Mastery table. 


Up to this point, this is totally doable.

 

Now, here's the difficult part:  There are empty dates the Mastery table. In our outcome table, if the [Initial Date Mastery] value is empty, look down for the earliest [Initial Date] that has a [Initial Date Mastery] value.

 

Same request for [Final Date Mastery]:  If the [Final Date Mastery] value is empty, look down for the earliest [Initial Date] with a [Final Date Mastery] and populate the [Final Date Mastery] field.

Here's an example:

 

User 111HT, in moduleID 473.  For [Initial Date] 7/30/2019 there's no Mastery value. The earliest Mastery value for that user, in that module is 3.5 on [Initial Date] 6/28/2019.  Thus, 3.5 should be populated in the row for 7/30/2019, as follows:

Screenshot 2023-07-24 130951.png

 

I hope this makes sense. I'm attaching an Excel sheet with sample data from the three tables.


Thank you!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@rgalvez , a new column based on what I got

 

diff =

var _max = maxx(filter(Table, [Rep Id] = earlier([Rep id])  && [Intial Date] < earlier([Intial date]) ), [Intial  Date])

return

 maxx(filter(Table, [Rep Id] = earlier([Rep id])  && [Intial Date] =_max ), [Score]) - [Score]

 

Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

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

3 REPLIES 3
arb1962
New Member

Hi Amit,

Here ia a scenario

Column 1 = date (take any random  years)

Column 2 to 4 = F1 F2 F3 ....F10 (platfroms) corresponding tweleve dates would have random 0 or 1 as an input for F1, F2 , F3 (represents 1 = issues, 0 = no issues) 

Column 5 - 8 are observations with heading Item 1 to Item 4. 

Item1 - Good, bad and Ok

Item2 - Low, Medium, High

Item3 - TK1, TK2, TK3

Item4 - BD1, BD2, BD3

 

All input for Item1 to Item4 random

 

I am looking for results based on Items versus Platfrom based on dates (yearly, quarterly, montly, weeky and even daily)

 

I tried to solve by unpivoting the platfroms and went for a solution but I am not getting the result. 

 

Could you help me out 

amitchandak
Super User
Super User

@rgalvez , a new column based on what I got

 

diff =

var _max = maxx(filter(Table, [Rep Id] = earlier([Rep id])  && [Intial Date] < earlier([Intial date]) ), [Intial  Date])

return

 maxx(filter(Table, [Rep Id] = earlier([Rep id])  && [Intial Date] =_max ), [Score]) - [Score]

 

Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

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

Thanks! Not exactly what I was asking for, but the link to the Earlier approach was very useful.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.