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! Learn more

Reply
Claudioffj
Regular Visitor

Filter current month and previous months

I have a table as shown below. It is possible to create calculated column so that when selecting month 3, for example, the result is month 3 plus months 2 and 1?

IDProj   Month  Year        Stats

1             1             2024     OK

2             2             2024     OK

3             3             2024     WIP

4             3             2024     WIP

5             4             2024     WIP

6             1             2024     OK

7             2             2024     OK

8             3             2024     WIP

9             3             2024     OK

10          4             2024     WIP

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Claudioffj ,

Please try this way:
Add a new table for creating the slicer:

vjunyantmsft_0-1709111263410.png

vjunyantmsft_1-1709111297599.png

Use this DAX to create the measure:

Measure = 
VAR _maxmonth = CALCULATE(MAX([Month]), FILTER(ALLEXCEPT('Table', 'Table'[ID]), [Month] <= SELECTEDVALUE(Slicer[Month])))
RETURN
IF( MAX([Month]) = _maxmonth, 1, 0)

Make the settings as shown in the figure below:

vjunyantmsft_2-1709111376306.png

The final output is as below:

vjunyantmsft_3-1709111403462.png
vjunyantmsft_4-1709111410741.png


Best Regards,
Dino Tao
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

11 REPLIES 11
Anonymous
Not applicable

Hi @Claudioffj ,

Please try this way:
Add a new table for creating the slicer:

vjunyantmsft_0-1709111263410.png

vjunyantmsft_1-1709111297599.png

Use this DAX to create the measure:

Measure = 
VAR _maxmonth = CALCULATE(MAX([Month]), FILTER(ALLEXCEPT('Table', 'Table'[ID]), [Month] <= SELECTEDVALUE(Slicer[Month])))
RETURN
IF( MAX([Month]) = _maxmonth, 1, 0)

Make the settings as shown in the figure below:

vjunyantmsft_2-1709111376306.png

The final output is as below:

vjunyantmsft_3-1709111403462.png
vjunyantmsft_4-1709111410741.png


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

Dino, thank you very much.

It helped me a lot.

Claudioffj
Regular Visitor

Does anyone have an idea?

Claudioffj
Regular Visitor

Can someone help me? I'm stuck on this problem and haven't been able to think of or come up with a solution for it yet.

Claudioffj
Regular Visitor

Sure @AmiraBedh, imagine a table with the data below.

 

ID

Month

Year

Stats

1

1

2024

OK

2

1

2024

OK

3

1

2024

WIP

4

2

2024

OK

5

2

2024

WIP

3

2

2024

WIP

3

3

2024

WIP

5

3

2024

WIP

 

I would like to present in a table the data for the month selected by the slicer and all the other data from previous months, but excluding duplicate IDs. So filtering month 3 in the data above, the table would need to look like this.

 

ID

Month

Year

Stats

1

1

2024

OK

2

1

2024

OK

4

2

2024

OK

3

3

2024

WIP

5

3

2024

WIP

 

Likewise, if I select month 2 in the slicer, it would look like this.

 

ID

Month

Year

Stats

1

1

2024

OK

2

1

2024

OK

4

2

2024

OK

5

2

2024

WIP

3

2

2024

WIP

Claudioffj
Regular Visitor

Unfortunately, the solutions they provided didn't work for me.
I was doing some more tests and forgot to mention. As it's a monthly report, it's possible for the IDs to repeat, so ID 10 could appear in month 5, month 4, month 3, and so on.
So when filtering for month 4, it should only show ID 10 from month 4 and all the others from previous months that don't repeat.
It would look something like this:

id10 - month 5 - wip
id9 - month 5 - wip
id10 - month 4 - ok
id9 - month 4 - wip
id10 - month 3 - ok
id6 - month 3 - ok
id10 - month 2 - ok
id5 - month 2 - ok
id10 - month 1 - ok

Table filtered for month 4:
id10 - month 4 - ok
id9 - month 4 - wip
id6 - month 3 - ok
id5 - month 2 - ok

Can you gather all the info and reshare it? the more you clarify your request, the more things will be easy for us ti help you.

 

Cumulative Stats = 
VAR SelectedMonth = MAX('Table'[Month])  -- Assumes a single month selection
RETURN
SUMX(
    FILTER(
        SUMMARIZE(
            'Table',
            'Table'[IDProj],
            "LatestMonth", MAXX(FILTER('Table', 'Table'[Month] <= SelectedMonth), 'Table'[Month]),
            "Stats", MAXX(FILTER('Table', 'Table'[Month] <= SelectedMonth), 'Table'[Stats])  -- Adjust this line as needed
        ),
        [LatestMonth] = SelectedMonth
    ),
    [Stats]
)

Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
AmiraBedh
Super User
Super User

You can create a measure for visibility and use it as a filter in your visual :

 

IsVisibleBasedOnMonth = 
VAR CurrentMonth = MAX('Table'[Month]) -- Current row month
VAR CurrentYear = MAX('Table'[Year]) -- Current row year
VAR SelectedMonth = SELECTEDVALUE('Table'[Month])
RETURN
IF(
    AND(CurrentYear = MAX('Table'[Year]), CurrentMonth <= SelectedMonth),
    1, 
    0
)

Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
Claudioffj
Regular Visitor

@AmiraBedh 

When I filter by month 3 for example, the data for January and February does not appear. In fact, I don't need to count, just show the data in a list table, listing the data according to the month filters applied.

selecting 3 in the filter..
ex. table
data month 3
data month 2
data month 1

Thanks

 

Hi,

I have solved a similar problem in the attached file.  On selecting a date, the table visual will show data for the 7 days ended the selected date.  You may apply the same logic for months as well.

Hope this helps.

Ashish_Mathur_0-1707617115759.png

 

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AmiraBedh
Super User
Super User

Create a slicer for the month and then a measure : 

 

ProjectsUpToSelectedMonth = 
VAR SelectedMonth = MAX(MyTab[Month]) 
VAR SelectedYear = MAX(MyTab[Year])
RETURN
CALCULATE(
    COUNTROWS(MyTab),
    MyTab[Year] = SelectedYear,
    MyTab[Month] <= SelectedMonth
)

Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors