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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
m4xon
Helper III
Helper III

Show previous "months", but based on the index column instead of date

Hi,

I have a weird case to solve. I would like to replace the logic of following measure (from SQLBI):

 

 

 

VAR NumOfMonths = -6
VAR ReferenceDate = MAX ( 'Date'[Date] )
VAR PreviousDates =
    DATESINPERIOD (
        'Previous Date'[Date],
        ReferenceDate,
        NumOfMonths,
        MONTH
    )
VAR Result =
    CALCULATE (
        SELECTEDMEASURE (),
        REMOVEFILTERS ( 'Date' ),
        KEEPFILTERS ( PreviousDates ),
        USERELATIONSHIP ( 'Previous Date'[Date], 'Date'[Date] )
    )
RETURN Result

 

 

 

but instead of using Date column I need to use Index one.

I have two not related tables called _txtCalendarTbl & _txtCalendar_Q_tbl:

TxtIndex
2022-1    1
2022-2    2
2022-3    3
2022-4    4
2023-1    5
2023-2    6
2023-3    7
2023-4    8
2024-1    9
2024-2    10
2024-3    11
2024-4    12
2025-1    13
2025-2    14
2025-3    15
2025-4    16
2026-1    17

as a source of a slicer I'm using _txtCalendarTbl and when I select for example 2024-4 I would like to be to see something like that:

_txtCalendarTbl Measure
2022-10
2022-20
2022-30
2022-40
2023-10
2023-20
2023-30
2023-40
2024-10
2024-20
2024-31
2024-41
2025-11
2025-20
2025-30
2025-40
2026-10

Thank you in advance!
Max

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@m4xon , Make sure you have a separate table with period and index. Joined back to your data table.

 

You can use measures like

 

This Period = CALCULATE(sum('Table'[Qty]), FILTER(ALL(Period),Period[Index]=max(Period[Index])))
Last Period = CALCULATE(sum('Table'[Qty]), FILTER(ALL(Period),Period[Index]=max(Period[Index])-1))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

Hi, thank you for your reply, it has led me to a solution:

Selected Period =
VAR _selectedPeriod =
    CALCULATE (
        MIN ( _txtCalendarTbl[Index] ),
        FILTER ( ALL ( _txtCalendar_Q_tbl), _txtCalendar_Q_tbl[Index] >= MAX ( _txtCalendar_Q_tbl[Index] ) - 1 ),
        FILTER ( ALL ( _txtCalendar_Q_tbl), _txtCalendar_Q_tbl[Index] <= MAX ( _txtCalendar_Q_tbl[Index] ) + 1 ),
        USERELATIONSHIP ( _txtCalendarTbl[Index], _txtCalendar_Q_tbl[Index] )
    )
RETURN
    IF ( ISBLANK ( _selectedPeriod ), BLANK() , 1 )

 

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@m4xon , Make sure you have a separate table with period and index. Joined back to your data table.

 

You can use measures like

 

This Period = CALCULATE(sum('Table'[Qty]), FILTER(ALL(Period),Period[Index]=max(Period[Index])))
Last Period = CALCULATE(sum('Table'[Qty]), FILTER(ALL(Period),Period[Index]=max(Period[Index])-1))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi, thank you for your reply, it has led me to a solution:

Selected Period =
VAR _selectedPeriod =
    CALCULATE (
        MIN ( _txtCalendarTbl[Index] ),
        FILTER ( ALL ( _txtCalendar_Q_tbl), _txtCalendar_Q_tbl[Index] >= MAX ( _txtCalendar_Q_tbl[Index] ) - 1 ),
        FILTER ( ALL ( _txtCalendar_Q_tbl), _txtCalendar_Q_tbl[Index] <= MAX ( _txtCalendar_Q_tbl[Index] ) + 1 ),
        USERELATIONSHIP ( _txtCalendarTbl[Index], _txtCalendar_Q_tbl[Index] )
    )
RETURN
    IF ( ISBLANK ( _selectedPeriod ), BLANK() , 1 )

 

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.