I would like to auto fill down the column 'Last Games Attendance' which is a measure and to show like the table below, this is an extension of an already correctly answered question that was from last month which I have added below.
Original question for reference. I have a table 'Date' with a column[Attendance] which has a mixture of values and zeros. I am looking for a code for Power BI that would display the previous attendance in a calculated column next to the attendance column so that I can use the information in a visual to show the difference of attendance between the 2 matchdays, unless there is a better way of doing this - Answered already in this link https://stackoverflow.com/a/78064438/12089221
Last Game Attendance Number =
VAR CurrentDate = 'Date'[Date]
VAR LastAttendanceDate =
MAXX(
FILTER(
'Date',
'Date'[Date] < CurrentDate && 'Date'[Attendance] > 0
),
'Date'[Date]
)
RETURN
IF(
'Date'[Attendance] = 0,
BLANK(),
LOOKUPVALUE('Date'[Attendance], 'Date'[Date], LastAttendanceDate)
)
New Query If site has zero in attendance then it was closed, could it auto-fill down from the result of the above measure, I originally asked for it to show 'Site Closed' but this isn't helping on a new dashboard I am creating. The below was the code I had originally asked for to show 'Site Closed'
Last Games Attendance Label =
IF('Date'[Last Game Attendance Number] = BLANK(), "Site Closed", FORMAT('Date'[Last Game Attendance Number], "0"))
The table below is how I would like it to look, where the code above would have populated the column 'Last Games Attendance' with 'Site Closed' if the attendance was zero.
Date | Attendance | Last Games Attendance |
---|---|---|
06/01/24 | 0 | 0 |
07/01/24 | 52314 | 0 |
08/01/24 | 0 | 52314 |
09/01/24 | 0 | 52314 |
10/01/24 | 16895 | 52314 |
11/01/24 | 0 | 16895 |
12/01/24 | 0 | 16895 |
13/01/24 | 48536 | 16895 |
14/01/24 | 78236 | 48563 |
15/01/24 | 12247 | 78263 |
16/01/24 | 0 | 78263 |
17/01/24 | 52314 | 12247 |
You need to add a calculated column and check if the LastAttendanceDate is blank. If it is, it means there was no previous game with attendees, so you return 0. Otherwise, the LOOKUPVALUE finds the attendance on the LastAttendanceDate :
Last Games Attendance =
VAR CurrentDate = 'Date'[Date]
VAR LastAttendanceDate = MAXX(
FILTER(
'Date',
'Date'[Date] < CurrentDate && 'Date'[Attendance] > 0
),
'Date'[Date]
)
RETURN
IF(
ISBLANK(LastAttendanceDate),
0,
LOOKUPVALUE('Date'[Attendance], 'Date'[Date], LastAttendanceDate)
)