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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi,
I have a problem with a measure that should return the last value for a given customer. Sample excel table:
| Date | Customer | Measure | Brand |
| 16.09.2021 | A | 100 | x |
| 16.09.2021 | B | 110 | x |
| 16.09.2021 | C | 120 | x |
| 16.09.2021 | D | 130 | x |
| 16.09.2021 | D | 5 | y |
| 16.09.2021 | E | 140 | x |
| 17.09.2021 | A | 150 | x |
| 17.09.2021 | B | 160 | x |
| 17.09.2021 | C | 170 | x |
| 17.09.2021 | E | 180 | x |
| 18.09.2021 | A | 190 | x |
| 18.09.2021 | B | 200 | x |
| 24.09.2021 | C | 210 | x |
I wrote the measure below:
Solved! Go to Solution.
Hi @Anonymous ,
Here's my solution.
1.Create a calendar table and there's no relationship between two tables.
Calendar = ADDCOLUMNS(CALENDARAUTO(),"Weeknum",WEEKNUM([Date],2))
2.Create a Weeknum column in Arkusz1 table.
Weeknum = WEEKNUM([Date],2)
3.Measure 3 is the measure you created.
Measure 2 = SUMX (
VALUES('Arkusz1'[Customer]),
CALCULATE ( SUM('Arkusz1'[Measure]), LASTDATE ( 'Arkusz1'[Date] ) )
)
4.Create the following measure
LastDateByWeeknumWithoutBlank =
var _value=CALCULATE([Measure 2],FILTER('Arkusz1',[Weeknum]=MAX('Calendar'[Weeknum])))
var _valuelastweek=CALCULATE([Measure 2],FILTER('Arkusz1',[Weeknum]=MAX('Calendar'[Weeknum])-1))
return
IF(_value=BLANK(),_valuelastweek,_value)
5.If you only want to limit the number of weeks to only the number of weeks in your main table.
Create a flag measure and put it into Filters.
flag = var _max=MAXX(ALL(Arkusz1),[Weeknum])
var _min=MINX(ALL(Arkusz1),[Weeknum])
return IF(_min<=MAX('Calendar'[Weeknum])&&_max>=MAX('Calendar'[Weeknum]),1)
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
Here's my solution.
1.Create a calendar table and there's no relationship between two tables.
Calendar = ADDCOLUMNS(CALENDARAUTO(),"Weeknum",WEEKNUM([Date],2))
2.Create a Weeknum column in Arkusz1 table.
Weeknum = WEEKNUM([Date],2)
3.Measure 3 is the measure you created.
Measure 2 = SUMX (
VALUES('Arkusz1'[Customer]),
CALCULATE ( SUM('Arkusz1'[Measure]), LASTDATE ( 'Arkusz1'[Date] ) )
)
4.Create the following measure
LastDateByWeeknumWithoutBlank =
var _value=CALCULATE([Measure 2],FILTER('Arkusz1',[Weeknum]=MAX('Calendar'[Weeknum])))
var _valuelastweek=CALCULATE([Measure 2],FILTER('Arkusz1',[Weeknum]=MAX('Calendar'[Weeknum])-1))
return
IF(_value=BLANK(),_valuelastweek,_value)
5.If you only want to limit the number of weeks to only the number of weeks in your main table.
Create a flag measure and put it into Filters.
flag = var _max=MAXX(ALL(Arkusz1),[Weeknum])
var _min=MINX(ALL(Arkusz1),[Weeknum])
return IF(_min<=MAX('Calendar'[Weeknum])&&_max>=MAX('Calendar'[Weeknum]),1)
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Maybe I will add that the dates on the visualization come from a different date table (calendarauto)
@Anonymous Maybe:
New Measure =
VAR __Customer = MAX('Table'[Customer])
VAR __Date = MAX('Table'[Date])
VAR __Value1 = SUMX ( VALUES ( Arkusz1[Customer] ), CALCULATE ( SUM(Arkusz1[Measure] ), LASTDATE ( Arkusz1[Date] ) )
VAR __MaxDate = MAXX(FILTER(ALL('Table'),[Customer]=__Customer && [Date]<__Date),[Date])
VAR __Value2 = SUMX ( VALUES ( Arkusz1[Customer] ), CALCULATE ( SUM(Arkusz1[Measure] ), 'Table'[Date] = __MaxDate ) )
)
RETURN
IF(ISBLANK(__Value1),__Value2,__Value1)
Something along those lines.
Unfortunately, it doesn't work for me:(
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 59 | |
| 46 | |
| 42 | |
| 23 | |
| 17 |
| User | Count |
|---|---|
| 190 | |
| 122 | |
| 96 | |
| 66 | |
| 47 |