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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
yaman123
Post Patron
Post Patron

Last 5 Week Trend

Hi, 

 

I am looking for a query to show the last 5 weeks from the date selected in the slicer. I have a slicer which is Week Commencing (Mon - Sun) and I would like to present the data as below. If I select date 26/02/2024, the table should show as below. If i select date 19/02/2024, the latest date in the table should be 19/02/2024 and 22/01/2024 included and so on...

 

The main table and date table are not linked. 

 

TIA

 

 29/01/202405/02/202412/02/202419/02/202426/02/2024
Accidents00001
Absence12003
Safety Obs11110
1 ACCEPTED SOLUTION
v-yaningy-msft
Community Support
Community Support

Hi, @yaman123 

 

Based on your description, I have created some measures to achieve the effect you are looking for. Following picture shows the effect of the display.

 

vyaningymsft_0-1709885710992.png

 

 

 

vyaningymsft_1-1709885710995.png

 

Measure:

Data from five weeks ago =

IF (

    SELECTEDVALUE ( 'Table'[Date] )

        >= SELECTEDVALUE ( 'Date'[Date] ) - 35

        && SELECTEDVALUE ( 'Table'[Date] ) <= SELECTEDVALUE ( 'Date'[Date] ),

    1,

    IF ( NOT ISFILTERED ( 'Date'[Date] ), SELECTEDVALUE ( 'Table'[Date] ) )

)

IsMondayDate =

IF ( WEEKDAY ( 'Date'[Date_DateMeasure], 2 ) = 1, 1, 0 )


IsMondayTable =

IF ( WEEKDAY ( 'Table'[Table_DateMeasure], 2 ) = 1, 1, 0 )


Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

 

 

View solution in original post

1 REPLY 1
v-yaningy-msft
Community Support
Community Support

Hi, @yaman123 

 

Based on your description, I have created some measures to achieve the effect you are looking for. Following picture shows the effect of the display.

 

vyaningymsft_0-1709885710992.png

 

 

 

vyaningymsft_1-1709885710995.png

 

Measure:

Data from five weeks ago =

IF (

    SELECTEDVALUE ( 'Table'[Date] )

        >= SELECTEDVALUE ( 'Date'[Date] ) - 35

        && SELECTEDVALUE ( 'Table'[Date] ) <= SELECTEDVALUE ( 'Date'[Date] ),

    1,

    IF ( NOT ISFILTERED ( 'Date'[Date] ), SELECTEDVALUE ( 'Table'[Date] ) )

)

IsMondayDate =

IF ( WEEKDAY ( 'Date'[Date_DateMeasure], 2 ) = 1, 1, 0 )


IsMondayTable =

IF ( WEEKDAY ( 'Table'[Table_DateMeasure], 2 ) = 1, 1, 0 )


Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

 

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.