Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I have a date table whereby I set the date range to the end of year as is recommended. But when I need to use that field to filter a measure (as is recommended instead of filtering with a column from a fact table) I need to get the value that is max date in the fact table as the max date from the date table will return nothing in the fact table.
e.g.
Sales table date range 01/01/2023 - 05/04/2023
Date table date range 01/01/2023 - 31/12/2023
------------------------------------------
measure:
Sales Last Month =
CALCULATE(
SUM('Sales'[Profit]),
'Date'[Date] = MAX('Date'[Date]) - 1,
ALLSELECTED('Date')
)
-------------------------------------------
The max date will return null as there is no max date of 31/12/2023 in the sales table what is a better way to rewrite this measure. keeping in view that the filter column should be from a dimension table not a fact table as is recommended.
Solved! Go to Solution.
Try this instead:
Try this instead:
@akhaliq7 A couple potential problems with this. First, subtracting 1 from a date does not give you last month, it just gives you the previous day. Are you trying to calculate the sales for the last month in the fact table that is within the range of your slicer? If that is the case then maybe something like this:
Measure =
VAR __MaxDate = MAX('Sales'[Date])
VAR __YearMonth = YEAR(__MaxDate) * 100 + MONTH(__MaxDate)
VAR __Table =
SUMMARIZE(
FILTER(ALLSELECTED('Sales'), YEAR([Date]) * 100 + MONTH([Date]) = __YearMonth),
[Date],
"__Profit", SUM('Sales'[Profit])
)
VAR __Result = SUMX( __Table, [__Profit])
RETURN
__Result
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
9 | |
8 | |
6 | |
5 |
User | Count |
---|---|
19 | |
17 | |
11 | |
9 | |
9 |