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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
edgarMunoz
Frequent Visitor

DAX Calculation - Find value based on day (relative)

Hi community,

I'm seeking some help to solve a challenge I'm facing to create a measure. 

 

I have a table with the structure below. Each account (AccountNumber column) has multiple records, which are based on updates happening in the source system. Althought there seems to be a trend on teh dates when the updates occur, the reality is the updates don't necessarilly occur in the same date for all the accounts (as an example, for the period covered in the information below, Account_1 and Account_2 had 12 updates). 

 

I need a measure to calculate the total balance for a specific date (usually month end). The challenges are:

1. There is not always a record for that specific date. For example, if the reference date is 30/11/2025, I will not find a specific record with that date for each account. So, I need to find the closest one. This would be something like a VLOOKUP in Excel using TRUE as a range_lookup parameter (find the closest one).

2. The measure must evaluate by account. If the reference date is 5/09/2025, the I need to find the record closest to the reference day by account (evaluting in ascending order)

 

As an example, if the reference day is 5/09/2025, the measure should output: $53,972.78:

- Account_1: Value from 4/09/2025 --> $22,197.28

- Account_2: Value from 4/09/2025 --> $29,275.50

- Account_3: Value from 2/09/2025 --> $2,500.00 (notice here there is an update on 6/09/2025, but the closest date when evaluting in ascending order is 2/09/2052)

 

RecordDateAccountNumberBalance
1/07/2025Account_10
5/08/2025Account_111178.03
2/09/2025Account_122197.28
4/09/2025Account_122197.28
12/09/2025Account_10
1/10/2025Account_110173.87
31/10/2025Account_110173.87
3/11/2025Account_121186.58
5/11/2025Account_111012.71
10/11/2025Account_10
1/12/2025Account_110850.22
23/12/2025Account_10
1/07/2025Account_20
5/08/2025Account_214880.22
2/09/2025Account_229275.5
4/09/2025Account_229275.5
12/09/2025Account_20
1/10/2025Account_214295.86
31/10/2025Account_214295.86
3/11/2025Account_229243.84
5/11/2025Account_214947.98
10/11/2025Account_20
1/12/2025Account_214541.29
23/12/2025Account_20
1/07/2025Account_30
3/07/2025Account_30
4/07/2025Account_30
5/08/2025Account_32978.63
2/09/2025Account_32500
6/09/2025Account_35504
12/09/2025Account_30
1/10/2025Account_32809.55
31/10/2025Account_32809.55
3/11/2025Account_35356.78
5/11/2025Account_32547.23
10/11/2025Account_30
1/12/2025Account_32500.69
23/12/2025Account_30
1 ACCEPTED SOLUTION
FreemanZ
Community Champion
Community Champion

hi @edgarMunoz ,

 

Not sure if i fully get you, supposing you have a reference date slicer fed with a disconnected dates table, you may try to write the measure like this:

Measure = 
SUMX(
    VALUES(balance[AccountNumber]),
    CALCULATE(
        MAXX(
            TOPN(1, FILTER(balance, balance[RecordDate]<=MAX(dates[Date])), balance[RecordDate]),
            balance[Balance]
        )
    )
)

 

it works like:

FreemanZ_0-1767844087182.png

FreemanZ_1-1767844140020.png

 

Please find more in the attachment.

View solution in original post

8 REPLIES 8
Olufemi7
Solution Supplier
Solution Supplier

Hello @edgarMunoz

 

You need a measure that finds the latest balance on or before a reference date per account, then sums across accounts. The correct DAX pattern uses `CALCULATE` with `MAX` to identify the latest date ≤ reference date, and then retrieves the balance.


 Step-by-Step DAX Solution

1. Balance as of Reference Date (per account)

BalanceAsOfDate =
VAR RefDate = SELECTEDVALUE ( 'Calendar'[Date] )
VAR LatestDate =
CALCULATE (
MAX ( Data[RecordDate] ),
FILTER ( Data, Data[RecordDate] <= RefDate )
)
RETURN
CALCULATE (
MAX ( Data[Balance] ),
FILTER ( Data, Data[RecordDate] = LatestDate )
)


• `SELECTEDVALUE('Calendar'[Date])` → reference date from your Date table.
• Finds the latest record date ≤ RefDate for the current account.
• Returns the balance at that date.

 

2. Total Across Accounts

TotalBalanceAsOfDate =
SUMX (
VALUES ( Data[AccountNumber] ),
[BalanceAsOfDate]
)


• Iterates over each account.
• Uses the measure above to get the balance as of the reference date.
• Sums them up.


 Example (Reference Date = 5/09/2025)

• Account_1 → 4/09/2025 → $22,197.28
• Account_2 → 4/09/2025 → $29,275.50
• Account_3 → 2/09/2025 → $2,500.00
Total = $53,972.78

 

Relevant Microsoft Documentation

 

FILTER function (DAX) - DAX | Microsoft Learn https://learn.microsoft.com/en-us/dax/filter-function-dax

 

CALCULATE function (DAX) - DAX | Microsoft Learn https://learn.microsoft.com/en-us/dax/calculate-function-dax

 

LASTNONBLANKVALUE function (DAX) - DAX | Microsoft Learn https://learn.microsoft.com/en-us/dax/lastnonblankvalue-function-dax

 

Use CALCULATE + FILTER + MAX to find the latest date ≤ reference date.
• Use SUMX to aggregate across accounts.
• If you want the closest date in either direction (before or after), you’d need a different approach using `MINX` with absolute differences.
• For month-end reporting, tie your reference date to the last day of the month in your Calendar table.

v-echaithra
Community Support
Community Support

Hi @edgarMunoz ,

Thank you @FreemanZ , @maruthisp , @ThxAlot , @Irwan for your inputs.
I just wanted to check if the issue has been resolved on your end, or if you require any further assistance. Please feel free to let us know, we’re happy to help!


Thank you 
Chaithra E.

FreemanZ
Community Champion
Community Champion

hi @edgarMunoz ,

 

Not sure if i fully get you, supposing you have a reference date slicer fed with a disconnected dates table, you may try to write the measure like this:

Measure = 
SUMX(
    VALUES(balance[AccountNumber]),
    CALCULATE(
        MAXX(
            TOPN(1, FILTER(balance, balance[RecordDate]<=MAX(dates[Date])), balance[RecordDate]),
            balance[Balance]
        )
    )
)

 

it works like:

FreemanZ_0-1767844087182.png

FreemanZ_1-1767844140020.png

 

Please find more in the attachment.

maruthisp
Super User
Super User

Hi @edgarMunoz ,

 

As per my understanding, tried to derive a solution in the below pbix file.

DAX Calculation - Find value based on day (relative).pbix


Hope this help to solve the problem. Please let me know if you have any further questions or need clarifications.

 

If this reply helped solve your problem, please consider clicking "Accept as Solution" so others can benefit too. And if you found it useful, a quick "Kudos" is always appreciated, thanks! 

 

Best Regards, 

Maruthi 

LinkedIn - http://www.linkedin.com/in/maruthi-siva-prasad/ 

X            -  Maruthi Siva Prasad - (@MaruthiSP) / X

ThxAlot
Super User
Super User

Easy enough,

ThxAlot_0-1767693916405.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Irwan
Super User
Super User

hello @edgarMunoz 

 

i might be misunderstood but i assumed the closest date will always be max date before the date selection.

Irwan_0-1767654355799.png

 

1. create a calendar date because as you mentioned above, not all date available.

Irwan_1-1767654735004.png

2. no need to create a relationship between calendar and fact tabl.

3. create 3 measure for each account because every account will have different closest date.

Account_1 =
var _Date =
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[RecordDate]<=SELECTEDVALUE('Calendar'[Date])&&
        'Table'[AccountNumber]="Account_1"
    ),
    'Table'[RecordDate]
)
Return
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[RecordDate]=_Date&&
        'Table'[AccountNumber]="Account_1"
    ),
    'Table'[Balance]
)
ccount_2 =
var _Date =
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[RecordDate]<=SELECTEDVALUE('Calendar'[Date])&&
        'Table'[AccountNumber]="Account_2"
    ),
    'Table'[RecordDate]
)
Return
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[RecordDate]=_Date&&
        'Table'[AccountNumber]="Account_2"
    ),
    'Table'[Balance]
)
ccount_3 =
var _Date =
MAXX(
  FILTER(
        ALL('Table'),
        'Table'[RecordDate]<=SELECTEDVALUE('Calendar'[Date])&&
        'Table'[AccountNumber]="Account_3"
    ),
    'Table'[RecordDate]
)
Return
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[RecordDate]=_Date&&
        'Table'[AccountNumber]="Account_3"
    ),
    'Table'[Balance]
)
4. create a measure for sum all three measures.
SUM Account = [Account_1]+[Account_2]+[Account_3]
 
Hope this will help.
Thank you.
 

Hi Irwan,
Thanks for your help. This is the right track, however, I have thousands of accounts, so creating a calculated by account is not feasible.

hello @edgarMunoz 

 

here is the adjustment.

Irwan_0-1767670802138.pngIrwan_1-1767670816209.pngIrwan_2-1767670825065.png

 

1. create a measure for each account balance (if you dont need this value, the you can skip this measure).

Account =
var _Date =
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[RecordDate]<=SELECTEDVALUE('Calendar'[Date])&&
        'Table'[AccountNumber]=SELECTEDVALUE('Table'[AccountNumber])
    ),
    'Table'[RecordDate]
)
Return
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[RecordDate]=_Date&&
        'Table'[AccountNumber]=SELECTEDVALUE('Table'[AccountNumber])
    ),
    'Table'[Balance]
)
2. create a measure for sum total of all account in closest date from date selection.
SUM Total =
var _Date =
SUMMARIZE(
    ADDCOLUMNS(
        ALL('Table'),
        "Closest Date",
        MAXX(
            FILTER(
                ALL('Table'),
                'Table'[RecordDate]<=SELECTEDVALUE('Calendar'[Date])&&
                'Table'[AccountNumber]=EARLIER('Table'[AccountNumber])
            ),
            'Table'[RecordDate]
        )
    ),
    'Table'[AccountNumber],
    [Closest Date],
    "Balance",
    MAXX(
        FILTER(
            ALL('Table'),
            'Table'[RecordDate]=[Closest Date]&&
            'Table'[AccountNumber]=EARLIER('Table'[AccountNumber])
        ),
        'Table'[Balance]
    )
)
Return
SUMX(
    _Date,
    [Balance]
)
 
Hope this will help.
Thank you.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.