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! Request now

Reply
Anonymous
Not applicable

New Measure to find value between two dates

Hi,

 

I’ve mapped a Power BI dashboard to a folder where a new excel file is uploaded at the beginning of every month.  I’ve built the Power BI dashboard to combine/merge these files together in to one large table within Power BI.  When a new excel file is added to the folder at the beginning of the month, when I refresh the Power BI dashboard, Power BI reaches out to the folder and brings in the contents of the latest file, ultimately adding it to the existing table in Power BI.

 

The merged table in Power BI is called 'Data Files'.  The table has nearly 70 columns but here is a condensed slimmed down version of the data/table in Power BI:

 

Name    Latest_A1C    Acct_Name    Diabetes_IND    Source Date                      Member ID

Jesse     5.1                 Ford                0                        02/01/2020                      0005

Matt      7.3                 BMW              1                        02/01/2020                      1001

Andy      6                   Dodge            1                        02/01/2020                      7000

Jesse      3.2                Ford                1                        03/01/2020                      0005

Matt      7                   BMW               1                        03/01/2020                      1001

Andy      5.9                Dodge             0                       03/01/2020                      7000

Jesse      1.1                Ford                1                        04/01/2020                      0005

Matt      7.7                BMW               1                        04/01/2020                      1001

Andy      6.0                Dodge             0                       04/01/2020                      7000

 

I'd like to create a new measure that will subtract the most recent value in the [Latest_A1C] field based on it's [Source Date] field from the second most recent value in the [Latest_A1C] field based on it's [Source Date] field for each member.

 

For example, based on the example above, I'd want the new created measure to return the following results for Jesse, Matt and Andy.

 

-2.1 for Jesse                     (1.1 minus 3.2 = -2.1)

 0.7 for Matt                      (7.7 minus 7    =  0.7)

 0.1 for Andy                     (6.0 minus 5.9  =  0.1)

 

I've posted this question earlier this weekend and another user started to help me.  However, I can't seem to get the solution to work.  Here is what I've tried creating without success:

 

Measure =
VAR __Name = MAX([Name])
VAR __LatestDate = MAX([Source Date])
VAR __SecondLatestDate = MAXX(FILTER('Data Files',[Source Date] <> __LatestDate),[Source Date])
VAR __Latest = MAXX(FILTER('Data Files',[Latest_A1C] = __LatestDate), [LATEST_A1C])
VAR __SecondLatest = MAXX(FILTER('Data Files',[Latest_A1C] = __SecondLatestDate), [LATEST_A1C])
RETURN
__Latest - __SecondLatest
 
Can you please assist me in getting the above to work.  It's probably close but I'm stuck.
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , try a new column like

column =
var _index = maxx(filter(table, [Name] = earlier([Name]) && [Acct_Name] = earlier([Acct_Name]) && [Source Date] < earlier([Source Date]) ) ,[Source Date])
return
maxx(filter(table, [Name] = earlier([Name]) && [Acct_Name] = earlier([Acct_Name]) && [Source Date] =_index ) ,[ Latest_A1C]) - [Latest_A1C]

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

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , try a new column like

column =
var _index = maxx(filter(table, [Name] = earlier([Name]) && [Acct_Name] = earlier([Acct_Name]) && [Source Date] < earlier([Source Date]) ) ,[Source Date])
return
maxx(filter(table, [Name] = earlier([Name]) && [Acct_Name] = earlier([Acct_Name]) && [Source Date] =_index ) ,[ Latest_A1C]) - [Latest_A1C]

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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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