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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
JustParagon
Frequent Visitor

Display data for previous month with Month-Year filter

I have 2 visuals that interact with my Month-Year Filter (Format MMMM YYYY):

Date_No_Duplicate = FORMAT(DATE(YEAR([CreatedDate]), MONTH([CreatedDate]), 1), "MMMM YYYY")


The 1st visual shows the selected month's data, and the 2nd visual is supposed to show the previous month's data of the selected month in filter. Each visual uses 3 measures in Y-axis.

JustParagon_0-1719220249699.png

I also have another Month-Year Filter (called Period) for the whole dashboard so I created a measure as a filter. I have included this within an IF condition in my measures so it will check if the month selected is also selected in Period filter.

SelectedPeriod =
VAR SelectedPeriodValues = VALUES('Table'[CreatedDate])
RETURN
IF (
    SELECTEDVALUE('Table'[Date_No_Duplicate]) IN SelectedPeriodValues,
    1,
    0
)

As for my issue in the 2nd visual (previous month), I've tried converting my date filter back to date type then using it (tried other date columns) as a filter by setting the relative date to the last 1 calendar month, but it's being set to May 1 - May 31 statically so it always results to no data. I also tried to create a separate measure to be used as a filter but, no luck.

Any other solutions?






1 ACCEPTED SOLUTION
JustParagon
Frequent Visitor

I was able to fix it. This worked for me:

PreviousPeriod =
VAR PeriodValues=
    CALCULATETABLE(VALUES('Table'[CreatedDate]), REMOVEFILTERS(DimDate))
VAR PreviousMonth= EDATE(SELECTEDVALUE('DimDate'[Month Year]), -1)

RETURN
IF (
    PreviousMonth IN PeriodValues,
    1,
    0
)
Then used it in my measures with an IF condition equals to 1. I also added
REMOVEFILTERS(DimDate) in my count measures included in the calculation.

View solution in original post

4 REPLIES 4
JustParagon
Frequent Visitor

I was able to fix it. This worked for me:

PreviousPeriod =
VAR PeriodValues=
    CALCULATETABLE(VALUES('Table'[CreatedDate]), REMOVEFILTERS(DimDate))
VAR PreviousMonth= EDATE(SELECTEDVALUE('DimDate'[Month Year]), -1)

RETURN
IF (
    PreviousMonth IN PeriodValues,
    1,
    0
)
Then used it in my measures with an IF condition equals to 1. I also added
REMOVEFILTERS(DimDate) in my count measures included in the calculation.

Hi @JustParagon ,

Congratulations on finding the appropriate solution through your own efforts, and I'm sure your thinking will be able to help other users on the forum.

 

 

Best Regards

Yilong Zhou

v-yilong-msft
Community Support
Community Support

Hi @JustParagon ,

We can use a date table and create a measure to meet your requirement.

1. Create a date table based on your date, there is no relationship between two tables.

Date =
ADDCOLUMNS (
    CALENDAR ( "2019/7/1", "2020/6/1" ),
    "year", YEAR ( [Date] ),
    "Month_name", FORMAT ( [Date], "mmm" ),
    "Month_number", MONTH ( [Date] )
)

vyilongmsft_0-1719283999540.png

2. Create a measure like this.

Measure =
VAR selected_ =
    SELECTEDVALUE ( 'Date'[Month_name] )
VAR Date_ =
    CALCULATE (
        MAX ( 'Date'[Date] ),
        FILTER ( 'Date', 'Date'[Month_name] = selected_ )
    )
RETURN
    IF (
        ISBLANK ( selected_ ),
        CALCULATE ( SUM ( 'Table'[Values] ) ),
        CALCULATE (
            SUM ( 'Table'[Values] ),
            FILTER ( 'Table', 'Table'[Date] <= Date_ )
        )
    )

vyilongmsft_1-1719284064838.jpeg

3. At last we need to add a month slicer based on Date[Month_name], and the result like this.

vyilongmsft_2-1719284099810.png

vyilongmsft_3-1719284138972.jpeg

 

 

 

Best Regards

Yilong Zhou

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

 

 

 

 

 

 

Hi @v-yilong-msft,

The right graph for the selected month-year's data is working properly. Here's the measure used for the light blue one (and there are 2 other measures for the remaining percentages that work as expected):

RightGraph =
IF (
[SelectedPeriod] = 1,
DIVIDE(
300 - ([CountCondition1] + [CountCondition2]),
300,
0
),
0
)
 And the SelectedPeriod measure, where CreatedDate column is used as a slicer for the whole dashboard with multiple selection (Month Year format), and Date_No_Duplicate is also a slicer with single selection (Month Year format) to filter the 2 graphs that I've provided.
SelectedPeriod =
VAR SelectedPeriodValues = VALUES('Table'[CreatedDate])
RETURN
IF (
SELECTEDVALUE('Table'[Date_No_Duplicate]) IN SelectedPeriodValues,
1,
0
)

 

 


As a solution, I tried this tutorial until 4:22 for the static filter: https://www.youtube.com/watch?v=CaFpeY1lPTI where DATESINPERIOD function was used. I used DimDate[Month Year] as a slicer and I modified the measure to display the previous month's data instead of the last 6 months:
LeftGraph =

VAR MaxDate = MAX('DimDate'[Date])
VAR PrevMonth = DATESINPERIOD('New Date'[Date], MaxDate, -1, MONTH)

RETURN

CALCULATE(

DIVIDE(300 - ([CountCondition1] + [CountCondition2]),
300,
0
),


REMOVEFILTERS(DimDate),
KEEPFILTERS(PrevMonth),
USERELATIONSHIP('DimDate'[Date], 'New Date'[Date]) -- Inactive

)


Unfortunately, it still did not work, because I checked which months are included in the graph by dragging the Month Year in the X-axis, and it returns ALL:

JustParagon_0-1719295069524.png

The right graph is affected, did the same thing with the X-axis, and it's still displaying correct values for a single month. So I guess the only problem here is either my filter or measure for the left graph to display previous month's data.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.