Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
I have a database of purchased items and their prices. But, on some months, there's no purchase of some items. The idea is to repeat the price of the last purchase until we buy the item again. This repetion shouldn't be limited. I've tried using the DAX code below, but I only get the value to repeat for one time. I must note that the variable Price is a column created directly on the table in Data View. Can someone help?
Current code:
Pre_Value =
VAR ItemGroup = 'Table'[Item]
VAR Date1 = 'Table'[Month-Year]
VAR Pre_Date = PREVIOUSMONTH('Table'[Month-Year])
VAR Prev_Val = CALCULATE(MAX('Table'[Price]),FILTER('Table','Table'[Item]=ItemGroup),FILTER('Table','Table'[Month-Year]=Pre_Date))
RETURN IF('Table'[Price]=BLANK(),Prev_Val,'Table'[Price])
Outcome example:
Item | Price | Month-Year | Pre_Value |
100519 | 2021-10 | ||
100793 | 2021-06 | ||
100793 | 95 | 2021-07 | 95 |
100793 | 67 | 2021-08 | 67 |
100793 | 2021-09 | 67 | |
100793 | 2021-10 |
Expected outcome:
Item | Price | Month-Year | Pre_Value |
100519 | 2021-10 | ||
100793 | 2021-06 | ||
100793 | 95 | 2021-07 | 95 |
100793 | 67 | 2021-08 | 67 |
100793 | 2021-09 | 67 | |
100793 | 2021-10 | 67 |
Solved! Go to Solution.
@rutealvesdc find the attached pbix. It has the desired result in both calculated column and measure
_fdColumn =
VAR _0 =
CALCULATE (
LASTNONBLANK ( t1[Date], 1 ),
FILTER (
ALL ( t1 ),
t1[Date] <= EARLIER ( t1[Date] )
&& t1[Item] = EARLIER ( t1[Item] )
&& NOT ( ISBLANK ( t1[Price] ) )
)
)
VAR _1 =
CALCULATE ( SUM ( t1[Price] ), FILTER ( ALL ( t1 ), t1[Date] = _0 ) )
RETURN
_1
_fdMeasure =
VAR _mxDate =
MAX ( dt[Date] )
VAR _2 =
CALCULATE (
MAX ( dt[Date] ),
FILTER ( ALL ( dt ), dt[Date] <= _mxDate && [_Price] <> 0 )
)
VAR _3 =
CALCULATE ( [_Price], ALL ( dt ), dt[Date] = _2 )
RETURN
_3
@rutealvesdc find the attached pbix. It has the desired result in both calculated column and measure
_fdColumn =
VAR _0 =
CALCULATE (
LASTNONBLANK ( t1[Date], 1 ),
FILTER (
ALL ( t1 ),
t1[Date] <= EARLIER ( t1[Date] )
&& t1[Item] = EARLIER ( t1[Item] )
&& NOT ( ISBLANK ( t1[Price] ) )
)
)
VAR _1 =
CALCULATE ( SUM ( t1[Price] ), FILTER ( ALL ( t1 ), t1[Date] = _0 ) )
RETURN
_1
_fdMeasure =
VAR _mxDate =
MAX ( dt[Date] )
VAR _2 =
CALCULATE (
MAX ( dt[Date] ),
FILTER ( ALL ( dt ), dt[Date] <= _mxDate && [_Price] <> 0 )
)
VAR _3 =
CALCULATE ( [_Price], ALL ( dt ), dt[Date] = _2 )
RETURN
_3
Thanks smpa01.
This worked for me.
Thank you!
@rutealvesdc did you try the solution yet? If yes, and it works please accept the solution.
Yes!
How can I share it with you? Can I send it to your e-mail?
Hi! Do you have any suggestion?
Item-Year-Month | Price | Item | Year | Month | Month-Year | Pre_Value |
10030420211 | 100304 | 2021 | 1 | 2021-01 | ||
10030420212 | 100304 | 2021 | 2 | 2021-02 | ||
10030420213 | 100304 | 2021 | 3 | 2021-03 | ||
10030420214 | 100304 | 2021 | 4 | 2021-04 | ||
10030420215 | 100304 | 2021 | 5 | 2021-05 | ||
10030420216 | 100304 | 2021 | 6 | 2021-06 | ||
10030420217 | 63,7226891 | 100304 | 2021 | 7 | 2021-07 | 63,7226891 |
10030420218 | 57,5616458 | 100304 | 2021 | 8 | 2021-08 | 57,5616458 |
10030420219 | 100304 | 2021 | 9 | 2021-09 | 57,5616458 | |
100304202110 | 100304 | 2021 | 10 | 2021-10 | ||
100304202111 | 100304 | 2021 | 11 | 2021-11 | ||
100304202112 | 100304 | 2021 | 12 | 2021-12 | ||
10030420221 | 100304 | 2022 | 1 | 2022-01 | ||
10030420222 | 100304 | 2022 | 2 | 2022-02 | ||
10030420223 | 100304 | 2022 | 3 | 2022-03 | ||
10030420224 | 100304 | 2022 | 4 | 2022-04 | ||
10030420225 | 100304 | 2022 | 5 | 2022-05 | ||
10030420226 | 100304 | 2022 | 6 | 2022-06 | ||
10030420227 | 100304 | 2022 | 7 | 2022-07 | ||
10030420228 | 100304 | 2022 | 8 | 2022-08 | ||
10030420229 | 100304 | 2022 | 9 | 2022-09 | ||
100304202210 | 100304 | 2022 | 10 | 2022-10 | ||
100304202211 | 100304 | 2022 | 11 | 2022-11 | ||
100304202212 | 100304 | 2022 | 12 | 2022-12 | ||
10051920211 | 100519 | 2021 | 1 | 2021-01 | ||
10051920212 | 100519 | 2021 | 2 | 2021-02 | ||
10051920213 | 100519 | 2021 | 3 | 2021-03 | ||
10051920214 | 100519 | 2021 | 4 | 2021-04 | ||
10051920215 | 100519 | 2021 | 5 | 2021-05 | ||
10051920216 | 100519 | 2021 | 6 | 2021-06 | ||
10051920217 | 100519 | 2021 | 7 | 2021-07 | ||
10051920218 | 606,03 | 100519 | 2021 | 8 | 2021-08 | 606,03 |
10051920219 | 100519 | 2021 | 9 | 2021-09 | 606,03 | |
100519202110 | 100519 | 2021 | 10 | 2021-10 | ||
100519202111 | 100519 | 2021 | 11 | 2021-11 | ||
100519202112 | 100519 | 2021 | 12 | 2021-12 | ||
10051920221 | 100519 | 2022 | 1 | 2022-01 | ||
10051920222 | 100519 | 2022 | 2 | 2022-02 | ||
10051920223 | 100519 | 2022 | 3 | 2022-03 | ||
10051920224 | 100519 | 2022 | 4 | 2022-04 | ||
10051920225 | 100519 | 2022 | 5 | 2022-05 | ||
10051920226 | 100519 | 2022 | 6 | 2022-06 | ||
10051920227 | 100519 | 2022 | 7 | 2022-07 | ||
10051920228 | 100519 | 2022 | 8 | 2022-08 | ||
10051920229 | 100519 | 2022 | 9 | 2022-09 | ||
100519202210 | 100519 | 2022 | 10 | 2022-10 | ||
100519202211 | 100519 | 2022 | 11 | 2022-11 | ||
100519202212 | 100519 | 2022 | 12 | 2022-12 | ||
10079320211 | 100793 | 2021 | 1 | 2021-01 | ||
10079320212 | 100793 | 2021 | 2 | 2021-02 | ||
10079320213 | 100793 | 2021 | 3 | 2021-03 | ||
10079320214 | 100793 | 2021 | 4 | 2021-04 | ||
10079320215 | 100793 | 2021 | 5 | 2021-05 | ||
10079320216 | 100793 | 2021 | 6 | 2021-06 | ||
10079320217 | 95 | 100793 | 2021 | 7 | 2021-07 | 95 |
10079320218 | 67 | 100793 | 2021 | 8 | 2021-08 | 67 |
10079320219 | 100793 | 2021 | 9 | 2021-09 | 67 | |
100793202110 | 100793 | 2021 | 10 | 2021-10 | ||
100793202111 | 100793 | 2021 | 11 | 2021-11 | ||
100793202112 | 100793 | 2021 | 12 | 2021-12 | ||
10079320221 | 100793 | 2022 | 1 | 2022-01 | ||
10079320222 | 100793 | 2022 | 2 | 2022-02 | ||
10079320223 | 100793 | 2022 | 3 | 2022-03 | ||
10079320224 | 100793 | 2022 | 4 | 2022-04 | ||
10079320225 | 100793 | 2022 | 5 | 2022-05 | ||
10079320226 | 100793 | 2022 | 6 | 2022-06 | ||
10079320227 | 100793 | 2022 | 7 | 2022-07 | ||
10079320228 | 100793 | 2022 | 8 | 2022-08 | ||
10079320229 | 100793 | 2022 | 9 | 2022-09 | ||
100793202210 | 100793 | 2022 | 10 | 2022-10 | ||
100793202211 | 100793 | 2022 | 11 | 2022-11 | ||
100793202212 | 100793 | 2022 | 12 | 2022-12 |
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the September 2025 Power BI update to learn about new features.