cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
jasemilly
Helper I
Helper I

show last value on or before selected date

Hi 

I have a table that contains daily balances for several accounts by date.  It doesn't have an entry for every date.

 

The user selects a date they are interested in, I would like to display each account by value on a Clutered bar chart.

 

I am trying to create a measure that will calculate a value.  If the an entry doesn't exist for the selected date I would like the value of last entry before the selected date.

 

This is what I have so far but is giving me the error max has been used in a true/false expression that is used as a table filter

 

 

LastValueAmmount =
    CALCULATE(
        [Total Value],
    FILTER(
        ALL('Statement Date'[Date]),
            LASTNONBLANK('Statement Date'[Date],[Total Value])
        )
        , 'Statement Date'[Date] <= MAX ( 'Statement Date'[Date] )
)

 

[Total Value] is a measure I have created and just totals the closing balance  field.

 

 

here is my model

 

DataModel.png

 

thank you for all help

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft
Microsoft

Here is one approach to do it.  I made a mock table called Table that doesn't have balances for every date, and a Date table that has all dates.

 

Latest Day Balance = var selecteddate = SELECTEDVALUE('Date'[Date])
var maxbalancedate = CALCULATE(MAX('Table'[BalanceDate]), ALL('Date'[Date]), 'Table'[BalanceDate]<=selecteddate)
return CALCULATE([Total], 'Date'[Date]=maxbalancedate)
 
If this works for you, please mark it as the solution.  Please let me know if any questions.
Regards,
Pat
 




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Please refer to this article to learn how to properly calculate balances:

https://www.sqlbi.com/articles/semi-additive-measures-in-dax/

For other common patterns, you can always use www.daxpatterns.com.

Best
D
mahoneypat
Microsoft
Microsoft

Here is one approach to do it.  I made a mock table called Table that doesn't have balances for every date, and a Date table that has all dates.

 

Latest Day Balance = var selecteddate = SELECTEDVALUE('Date'[Date])
var maxbalancedate = CALCULATE(MAX('Table'[BalanceDate]), ALL('Date'[Date]), 'Table'[BalanceDate]<=selecteddate)
return CALCULATE([Total], 'Date'[Date]=maxbalancedate)
 
If this works for you, please mark it as the solution.  Please let me know if any questions.
Regards,
Pat
 




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@mahoneypat, @jasemilly...

The solution you gave and accepted is not correct if you have different accounts and the last date recorded for each account can be different.

Best
D

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors