Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have a table where I have added a column with an IF statment
RowNumberYear = IF(VALUE(MAX('gt EMPLOYEE'[YEAR])) = VALUE('Head Count'[YEAR]), 1, 0)
I am trying to get Max value using following expression:
RowNumber =
var FilteredTable =
FILTER('Head Count', 'Head Count'[RowNumberYear] = 1)
RETURN
MAX(FilteredTable[MONTH])
I am getting the following error message:
Table variable 'FilteredTable' cannot be used in current context because a base table is expected.
Any help is appreciated.
Thanks,
Ali.
Solved! Go to Solution.
Hi @Irwan ,
I tried the expression you provided, it gives me the 'MAX' for all the rows in the dataset.
So in my dataset I have a column 'MONTH' and 'YEAR' and I need to get a calculated column that gives me 1 for 'MAX' month and 'MAX' year, and 0 for all the remainder rows. The current dataset got max year as 2025 and max month as 5, and in my column I need 1 for MAX year 2025 and MAX month 5 and 0 for remainder of the rows. This should switch when the June data is added to the dataset.
I hope I have clarify the ask.
Thanks,
Ali.
Hi aliahad,
The error you're encountering in Power BI DAX, is due to the fact that you're trying to use a table variable (FilteredTable) directly inside a scalar function like MAX(), which expects a column reference from a base table, not a variable.
Please try below DAX expression:
RowNumber =
CALCULATE(
MAX('Head Count'[MONTH]),
'Head Count'[RowNumberYear] = 1
)
Hope the above DAX expression may help you.
Please let me know if you have further questions.
If this reply helped solve your problem, please consider clicking "Accept as Solution" so others can benefit too. And if you found it useful, a quick "Kudos" is always appreciated, thanks!
Best Regards,
Maruthi
hello @aliahad
as far as my knowledge, MAX() only accept column that has been defined.
DAX doesnt accept force command as my example above.
instead, you can do as below.
Hope this will help.
Thank you.
Hi @Irwan ,
I tried the expression you provided, it gives me the 'MAX' for all the rows in the dataset.
So in my dataset I have a column 'MONTH' and 'YEAR' and I need to get a calculated column that gives me 1 for 'MAX' month and 'MAX' year, and 0 for all the remainder rows. The current dataset got max year as 2025 and max month as 5, and in my column I need 1 for MAX year 2025 and MAX month 5 and 0 for remainder of the rows. This should switch when the June data is added to the dataset.
I hope I have clarify the ask.
Thanks,
Ali.
hello @aliahad
i assumed you want to get MAX value of your date (max month AND max year).
Here is a simple example.
Check =
var _Max = MAX('Table'[Date])
Return
IF(
'Table'[Date]=_Max,
1,
0
)
but if you need separate column between month and year, then please try this.
Check Month =
var _Max = MAX('Table'[Month])
Return
IF(
MONTH('Table'[Date])=_Max,
1,
0
)
Check Year =
var _Max = MAX('Table'[Year])
Return
IF(
YEAR('Table'[Date])=_Max,
1,
0
)
Hope this will help.
Thank you.
Hi @Irwan
I don't have a date field in my dataset, the MONTH and YEAR are the only fields available for me and I need to get the MAX of the year then the MAX of the month from the dataset.
Thanks,
Ali.
Hi @Irwan
The DAX expression you provided is giving me max value for all the rows.
Column = CALCULATE(
MAX('Head Count'[MONTH]),
FILTER('Head Count', 'Head Count'[RowNumberYear] = 1)
)
So in my dataset I have YEAR and MONTH, and I trying to get 1 or 0 in the calculated column for max year and month, so the current max month I got in the dataset is 5 and current max year is 2025, but when I new data for June I want current max month = 6 and current max year = 2025 and next month the max month will be July. So I am trying to create a flag using the calculated column.
Thanks,
Ali.
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
24 | |
9 | |
7 | |
6 | |
6 |
User | Count |
---|---|
29 | |
11 | |
11 | |
10 | |
6 |