Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Solved! Go to Solution.
Thank you very much Fowmy for your prompt reply.
This is the principle of slicers. When you select a month in a slicer, it will only show data relevant to your selection.
I recommend you create a date table as a slicer, but be careful not to create a relationship between the date table and the original table.
Here's some dummy data
"Query1"
Create a Date table.
Date =
SELECTCOLUMNS(
'Query1',
"Date",
'Query1'[SetupDate],
"Year",
'Query1'[SetupDate].[Year],
"Month",
'Query1'[SetupDate].[MonthNo]
)
Select Year and Month from the Date table as slicers.
Create a measure.
PreviousMonthCount =
VAR SelectYear = SELECTEDVALUE('Date'[Year])
VAR SelectMonth = SELECTEDVALUE('Date'[Month])
VAR PreviousMonthDate = EOMONTH(DATE(SelectYear, SelectMonth, 1), -1)
RETURN
CALCULATE(
SUM(Query1[NewCount]),
FILTER(
ALL('Query1'),
MONTH('Query1'[SetupDate]) = MONTH(PreviousMonthDate)
&&
YEAR('Query1'[SetupDate]) = YEAR(PreviousMonthDate)
&&
'Query1'[SetupDate] <= PreviousMonthDate
)
)
Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you very much Fowmy for your prompt reply.
This is the principle of slicers. When you select a month in a slicer, it will only show data relevant to your selection.
I recommend you create a date table as a slicer, but be careful not to create a relationship between the date table and the original table.
Here's some dummy data
"Query1"
Create a Date table.
Date =
SELECTCOLUMNS(
'Query1',
"Date",
'Query1'[SetupDate],
"Year",
'Query1'[SetupDate].[Year],
"Month",
'Query1'[SetupDate].[MonthNo]
)
Select Year and Month from the Date table as slicers.
Create a measure.
PreviousMonthCount =
VAR SelectYear = SELECTEDVALUE('Date'[Year])
VAR SelectMonth = SELECTEDVALUE('Date'[Month])
VAR PreviousMonthDate = EOMONTH(DATE(SelectYear, SelectMonth, 1), -1)
RETURN
CALCULATE(
SUM(Query1[NewCount]),
FILTER(
ALL('Query1'),
MONTH('Query1'[SetupDate]) = MONTH(PreviousMonthDate)
&&
YEAR('Query1'[SetupDate]) = YEAR(PreviousMonthDate)
&&
'Query1'[SetupDate] <= PreviousMonthDate
)
)
Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Fowmy What should be the query for CurrentMonth Last Year based on slicer selection?
@homelander123
Try this:
CurrentMonthLastYearCount =
VAR SelectedMonth = MAX(Query1[SetupDate])
VAR LastYearSameMonthStart = EOMONTH(SelectedMonth, -12) + 1
VAR LastYearSameMonthEnd = EOMONTH(SelectedMonth, -12)
RETURN
CALCULATE(
SUM(Query1[NewCount]),
Query1[SetupDate] >= LastYearSameMonthStart && Query1[SetupDate] <= LastYearSameMonthEnd
)
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
PreviousMonthCount =
VAR SelectedMonth = MAX(Query1[SetupDate])
RETURN
CALCULATE(
SUM(Query1[NewCount]),
Query1[SetupDate] >= EOMONTH(SelectedMonth, -2) + 1 && Query1[SetupDate] <= EOMONTH(SelectedMonth, -1)
)
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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 |
---|---|
16 | |
13 | |
12 | |
11 | |
11 |
User | Count |
---|---|
19 | |
14 | |
14 | |
11 | |
9 |