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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
miguelmkuk
Frequent Visitor

Last Values with contextual filters

Hello,

 

I have a set of data summarised as below:

 

DateAccountBalance
26/03/2023B50
12/03/2023D10
26/02/2023C500
12/02/2023B200
29/01/2023D100
15/01/2023C1000
01/01/2023B400
18/12/2022D50
04/12/2022C10
11/09/2022C500
28/08/2022D200
14/08/2022A100
31/07/2022C1000
08/05/2022D400
24/04/2022B50
10/04/2022A10
27/03/2022C500
13/03/2022D200
27/02/2022D100
13/02/2022D1000
30/01/2022B400
07/11/2021B50
12/09/2021A10
29/08/2021C500
15/08/2021B200
01/08/2021A100


"Date" column, which is the date the value of column "Balance" changes/updates. The "Date" column is linked to the Calendar table in the data model.

"Account" column, which is the name of the account the "Balance" column relates to. The number and name of accounts is variable (new accounts will be created and existing accounts will be closed)

"Balance" column contains the values to be evaluated.

I want to create a measure that returns the balance in a given date (filtered by the calendar table) regardless the the set of data contains an entry for that date or not. If there is an entry, it's straight forward but if there isn't, the measure has to look for the last time the value was updated (maybe months or years ago) for the related account (other accounts might have been updated recently)

I've tried for many hours with commands such as LASTNONBLANK() but always get a lot of problems.

The contextual filters must still work as I will use the measure in a pivot table with data sorted by the Calendar dates and by the account names (and others)

 

Thank you very much.

 

Kind regards
Miguel

 

Captura de pantalla 2023-04-16 141803.png

1 ACCEPTED SOLUTION

Hello,

 

I solved my problem with the help of the following article:

https://exceleratorbi.com.au/fill-table-with-last-survey-result/

 

Then I needed to itterate the formula based on distinct values of the "Account" column. Chat GPT did this part for me!!

View solution in original post

4 REPLIES 4
miguelmkuk
Frequent Visitor

Hello,


I haven't managed to find the solution to this yet.

A ver similar thread I found in this forum: LASTNONBLANK Explained - Excelerator BI
but yet, they do not do the formula I need.

I've asked for help in that other forum also but no answer, if you can help in the meantime would be very much appreciated.

In that other forum example, the question would be:

" How should it be the formula if in addition to the current return values, I need to:

1. return values in those periods that there is no entry, i.e. to carry on the value from the previous period.
Example: May 2016, Kathy: 1,474 (rather than blank)

2. (Once point 1 is achieved) removing the “account” contextual filter so I can see the sum of all account balances at a moment in time.
e.g. balance for May 2016: 3,280 (1,474 from account “Kathy” and 1,806 from account “Matt”)

I’ve been trying to obtain this for many many hours and couldn’t manage to do it. I’m not an expert of DAX at all but couldn’t find anything clear about this despite I believe must be a usual application."

 

Thank you!

Hello,

 

I solved my problem with the help of the following article:

https://exceleratorbi.com.au/fill-table-with-last-survey-result/

 

Then I needed to itterate the formula based on distinct values of the "Account" column. Chat GPT did this part for me!!

miguelmkuk
Frequent Visitor

Thank you @FreemanZ

 

This is very good progress for me!

 

My main goal is to find the latest balance of any accounts for any given period/date.

I've implemented your advise as per screenshots below and displayed the results in a Pivot Table.
I've then copied the table next to it and add manually the additional results I'd like to get.

DAX Measure "Last Balance"

Captura de pantalla 2023-04-16 201145.png

 

Relationship between Data[Date] and Calendard[Date]

Captura de pantalla 2023-04-16 201051.png

 

"Last Balance" measure results in Pivot Table and comments about additional needs/modifications.

Captura de pantalla 2023-04-16 200901.png

 

Hope it makes sense to you and can help me a bit more.

Thank you very much

 

Kind regards

miguelmkuk

FreemanZ
Super User
Super User

hi @miguelmkuk 

not sure if i fully get you. try to plot a visual with Data[Account] column and a measure like:

 

Measure = 
VAR _date= MAX(Dates[Date])
VAR _account = MAX(Data[Account])
VAR _table =
    FILTER(    
        ALL(Data),
        Data[Account]=_account
            &&Data[Date]<=_date
    )
VAR _maxdate =    
    MAXX(
        _table,
        Data[Date]
    )
VAR _balance =
    MAXX(
        FILTER(_table,Data[Date]=_maxdate),
        Data[Balance]
    )
RETURN 
    _balance

 

 

it worked like:

FreemanZ_0-1681653302257.png

 

FreemanZ_1-1681653356148.png

The Date slicer is with Dates[Date] column. 

 

You see, the point is identify the proper last date. 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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