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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
amehrosh
Frequent Visitor

Last 12 months based on Year and Month Name selection

Hi.

I have a requirement wherein client wants to see last 12 months data based on the selected Year and Month Name selection.

Suppose if I select 2023 in Year and Month Name as Jan, then it should show us the data from Jan 2023 to Feb 2022 i.e.12 months.

Any help is appreciated.
Thanks,
Alina

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @amehrosh ,

Please create measure with below dax formula:

Measure =
VAR cur_year =
    SELECTEDVALUE ( 'Table 2'[Year] )
VAR cur_month =
    SELECTEDVALUE ( 'Table 3'[Month] )
VAR _month =
    SWITCH (
        cur_month,
        "Jan", 1,
        "Feb", 2,
        "Mar", 3,
        "Apr", 4,
        "May", 5,
        "Jun", 6,
        "Jul", 7,
        "Aug", 8,
        "Sep", 9,
        "Oct", 10,
        "Nov", 11,
        "Dec", 12
    )
VAR max_date =
    DATE ( cur_year, _month, 1 )
VAR tmp =
    DATESINPERIOD ( 'Table 4'[Date], max_date, -12, MONTH )
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Date] )
RETURN
    IF ( cur_date IN tmp, 1 )

Add a matrix visual and add this measure to filter pane and apply:

vbinbinyumsft_0-1676257667456.png

 

 

For more details, please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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

3 REPLIES 3
Anonymous
Not applicable

Hi @amehrosh ,

Please create measure with below dax formula:

Measure =
VAR cur_year =
    SELECTEDVALUE ( 'Table 2'[Year] )
VAR cur_month =
    SELECTEDVALUE ( 'Table 3'[Month] )
VAR _month =
    SWITCH (
        cur_month,
        "Jan", 1,
        "Feb", 2,
        "Mar", 3,
        "Apr", 4,
        "May", 5,
        "Jun", 6,
        "Jul", 7,
        "Aug", 8,
        "Sep", 9,
        "Oct", 10,
        "Nov", 11,
        "Dec", 12
    )
VAR max_date =
    DATE ( cur_year, _month, 1 )
VAR tmp =
    DATESINPERIOD ( 'Table 4'[Date], max_date, -12, MONTH )
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Date] )
RETURN
    IF ( cur_date IN tmp, 1 )

Add a matrix visual and add this measure to filter pane and apply:

vbinbinyumsft_0-1676257667456.png

 

 

For more details, please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

FreemanZ
Community Champion
Community Champion

hi @amehrosh 

 

it seems you expect a measure. How do you plan to showcase this measure? What context do you have, like axis, row/column of a visual?

measure to show in a matrix.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.