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.
Hello everyone,
I am trying to write some DAX to have a calculated field in a calendar table. This table is created by:
Ok, thanks – I think I've just done what you recommended:
First I created this measure to calculate last month across the dataset
last_month = MAXX(FILTER(ALLSELECTED(Table_name),Table_name[month]>1),Table_name[month])
Then this one to convert existing month column (integer between 1 and 12) into a measure:
month_ = CALCULATE(
AVERAGE(Table_name[month]),
ALLEXCEPT(Table_name,Table_name[month])
)
...and then this final measure, to flag months which are the last ones according to filters as "Yes" else as "No":
last_month_flag = IF(Table_name[month_] = Table_name[last_month],"Yes","No")
It works indeed:
My end goal is to use this last_month_flag as a grouping variable for aggregating sessions and have a sub-total for all the last_month_flag = "No" months to compare against the most recent month (last_flag_month = "Yes").
What is the best way to use this measure to aggregate other measures?
I have created a parameter out of this last_month_flag measure and written a measure for a KPI I need to summarize, but while I manage to summarize values for all the "No" months (monthly averages), the values for the last month are missing and so the labels "Yes" and "No" as the parameter/last_month_flag is being used as grouping parameter by row. I know, it's a lot. Below the KPI measure:
KPI =
var tb =
SUMMARIZE (
CALCULATETABLE(
'Table_name'
),
'Table_name'[month],
"SUM",
CALCULATE(
SUM(Table_name[Sessions])
)
)
return
IF('Table_name'[last_month_flag]="No",CALCULATE(AVERAGEX(tb, CALCULATE(SUM(Table_name[Sessions]))),FILTER('Table_name','Table_name'[last_month_flag]="No")),CALCULATE(SUM(Table_name[Sessions]))
)
You can't do it in a table, calculated tables and columns are only calculated during data load or refresh, so they don't pay any attention to filters or slicers. If you need something to react dynamically you need to use a measure.
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 |
---|---|
10 | |
9 | |
8 | |
7 | |
6 |
User | Count |
---|---|
14 | |
13 | |
11 | |
9 | |
8 |