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
tmhalila
Resolver I
Resolver I

Get the last value submitted

Hello there,

I have a dataset that tracks weekly performance but data are submitted on daily from different branches. I have written a measure that dynamically selects the last record submitted based on the week selected from the slicer.

cummulative_indicators = 
CALCULATE(SUM('dataset'[cummulative_indicator]),LASTDATE(dim_date[date])
)

 

The only challenge here I am missing those branches that submitted data at the beginning or in the middle of the reporting week but not on the last date of the week. Example a branch with branch ID 105864-3

 

Here is the Power BI project your support is appreciated.

1 ACCEPTED SOLUTION
tmhalila
Resolver I
Resolver I

Hello,

I have managed to solve with below functions

cummulative = 
  VAR SelectedStartDate = MIN (dim_date[date])
  VAR SelectedEndDate = MAX (dim_date[date])

RETURN
    SUMX (
        VALUES('dataset'[branch_id]),
        VAR LatestDate =
            CALCULATE (
                MAX ('dataset'[report_date]),
                'dataset'[branch_id]
                    = EARLIER('dataset'[branch_id])
                    && 'dataset'[report_date] >= SelectedStartDate
                    && 'dataset'[report_date] <= SelectedEndDate
            )
        RETURN
            CALCULATE (
                SUM ('dataset'[cummulative_indicator]),
                'dataset'[branch_id]
                    = EARLIER ( 'dataset'[branch_id])
                    && 'dataset'[report_date] = LatestDate
            )
    )

View solution in original post

3 REPLIES 3
tmhalila
Resolver I
Resolver I

Hello,

I have managed to solve with below functions

cummulative = 
  VAR SelectedStartDate = MIN (dim_date[date])
  VAR SelectedEndDate = MAX (dim_date[date])

RETURN
    SUMX (
        VALUES('dataset'[branch_id]),
        VAR LatestDate =
            CALCULATE (
                MAX ('dataset'[report_date]),
                'dataset'[branch_id]
                    = EARLIER('dataset'[branch_id])
                    && 'dataset'[report_date] >= SelectedStartDate
                    && 'dataset'[report_date] <= SelectedEndDate
            )
        RETURN
            CALCULATE (
                SUM ('dataset'[cummulative_indicator]),
                'dataset'[branch_id]
                    = EARLIER ( 'dataset'[branch_id])
                    && 'dataset'[report_date] = LatestDate
            )
    )
Jamie_Scott
Resolver II
Resolver II

Try the below,

 

It gets the first and last date of the selected week from the slicer, and then uses filter to include all dates in this range of dates.

 

cummulative_indicators =
CALCULATE(
SUM('dataset'[cummulative_indicator]),
FILTER(
ALL(dim_date[date]),
dim_date[date] >= MIN(dim_date[date]) && dim_date[date] <= MAX(dim_date[date])
)
)

I got it from ChatGPT it doesn't work and it gives out the wrong results, And took too long to compute since the actual dataset has more than 5M records.

 

What I am looking for is when "Branch A" submits a report for the week of 27 Nov 2023 - 03 Dec 2023 on 27 and 29 then other "Branches" submit their reports up to 03 For others I will pick all values submitted on 03 which is end of the week but I'll also include the value for "Branch A" on 29.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.