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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
fbittencourt
Advocate II
Advocate II

Filter a visual by last month

I need to filter a visual by last month, my model does not have a date table. I need to apply a mesure or a calculated column to filter

 

My month[Mois] data contains 1 to 13 I need to not include 13 month as last when applied

 

fbittencourt_0-1736842862315.png

 

I tried this mesure but how can I apply it?

Mois max = CALCULATE(MAX(FAIT_INDICATEURS[MOIS]),FILTER(FAIT_INDICATEURS,FAIT_INDICATEURS[MOIS]
    ))
 
This mesure is apllied on the values 
Nb_Personnes = CALCULATE (
DISTINCTCOUNT ( REF_RESSOURCE[UID ressource] ),
FILTER(REF_RESSOURCE,REF_RESSOURCE[Rôle] <> "GEN" &&FAIT_INDICATEURS[Charge HTP]<>0
 
1 ACCEPTED SOLUTION

fbittencourt_0-1736851413502.png

Using the filter works properly thank for your quick answer.

 

The combination of the mesures has an error so I applied the first option

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @fbittencourt ,

 

To filter a visual by the last month in your dataset without using a date table, you can achieve this by creating a DAX measure that dynamically calculates the latest month, ensuring that month 13 is excluded from being considered as the last month.

Start by creating a measure to determine the latest month from your [MOIS] column, considering only values from 1 to 12. The following DAX measure will calculate the highest month number, excluding 13:

LastMonth = 
VAR MaxMois = MAXX(FILTER(FAIT_INDICATEURS, FAIT_INDICATEURS[MOIS] <= 12), FAIT_INDICATEURS[MOIS])
RETURN MaxMois

Next, incorporate this measure into your existing Nb_Personnes measure to filter the visual by the last month. Here’s the updated measure that filters by the calculated LastMonth value:

Nb_Personnes = 
VAR LastMonthValue = 
    MAXX(FILTER(FAIT_INDICATEURS, FAIT_INDICATEURS[MOIS] <= 12), FAIT_INDICATEURS[MOIS])
RETURN
CALCULATE(
    DISTINCTCOUNT(REF_RESSOURCE[UID ressource]),
    FAIT_INDICATEURS[MOIS] = LastMonthValue,
    REF_RESSOURCE[Rôle] <> "GEN",
    FAIT_INDICATEURS[Charge HTP] <> 0
)

This measure calculates the number of unique resources for the last month by dynamically determining the maximum month value that is 12 or less. The CALCULATE function applies this filter alongside the conditions to exclude certain roles and ensure that only rows with non-zero values in the Charge HTP column are counted.

If you prefer to apply the last month filter directly within the visual without modifying the existing measure, you can also add a filter on the [MOIS] column in the Filters pane. Set it to show the top 1 value by [MOIS] and apply an additional condition to exclude month 13 by setting the filter to [MOIS] <= 12.

These steps will ensure that your visual always reflects data from the most recent month in your dataset, excluding any values from the 13th month.

 

Best regards,

 

fbittencourt_0-1736851413502.png

Using the filter works properly thank for your quick answer.

 

The combination of the mesures has an error so I applied the first option

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.