Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
homelander123
Helper I
Helper I

Dax not working

PreviousMonthCount = CALCULATE(SUM(Query1[NewCount] ),
FILTER(
    Query1,
    FORMAT(Query1[SetupDate], "yyyyMM") =
    FORMAT(EDATE(SELECTEDVALUE(Query1[SetupDate]),-1),"yyyyMM")

))


I am trying to use this query to show the previous month based on the month selected in the slicer but it is giving me no values in the table
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @homelander123 

 

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"

vnuocmsft_0-1739780112195.png

 

Create a Date table.

 

Date = 
SELECTCOLUMNS(
    'Query1',
    "Date",
    'Query1'[SetupDate],
    "Year",
    'Query1'[SetupDate].[Year],
    "Month",
    'Query1'[SetupDate].[MonthNo]
)

 

vnuocmsft_1-1739780148981.png

 

Select Year and Month from the Date table as slicers.

 

vnuocmsft_2-1739780202658.png

 

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.

 

vnuocmsft_3-1739780295851.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @homelander123 

 

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"

vnuocmsft_0-1739780112195.png

 

Create a Date table.

 

Date = 
SELECTCOLUMNS(
    'Query1',
    "Date",
    'Query1'[SetupDate],
    "Year",
    'Query1'[SetupDate].[Year],
    "Month",
    'Query1'[SetupDate].[MonthNo]
)

 

vnuocmsft_1-1739780148981.png

 

Select Year and Month from the Date table as slicers.

 

vnuocmsft_2-1739780202658.png

 

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.

 

vnuocmsft_3-1739780295851.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

homelander123
Helper I
Helper I

@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
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy  This is not returning any data - Its blank 

Fowmy
Super User
Super User

@homelander123 

PreviousMonthCount = 
VAR SelectedMonth = MAX(Query1[SetupDate])
RETURN 
CALCULATE(
    SUM(Query1[NewCount]),
    Query1[SetupDate] >= EOMONTH(SelectedMonth, -2) + 1 && Query1[SetupDate] <= EOMONTH(SelectedMonth, -1)
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.