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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Line graph with previous period rather than previous 7 days

I have a line graph that currently compares current 7 days to previous 7 days.

 

The current 7 days is from my table / database

The previous 7 days line is being calculated with this measure:

asfgasfasf_0-1632145978174.png

 

My graph looks like this:

asfgasfasf_1-1632146019416.png

e.g. on the 19th it shows data for the 19th and also the data for the 12th

 

I want this graph to be more dynamic. To update the previous period depending on the days in the current period.

 

This is the new previous period measure I am trying to use:

asfgasfasf_3-1632146257824.png

 

I am using the dates 13/09/2021 to 19/09/2021. This gives a date difference of -6 days. Subtract 1 more so the date periods do not overlap. My new graph looks like this:

asfgasfasf_4-1632146393383.png

The previous period value now shows the value from the previous day rather than 7 days ago.

 

Any help would be appreciated. Thanks. 

 

 

 

 

2 ACCEPTED SOLUTIONS
MFelix
Super User
Super User

Hi @Anonymous ,

 

This is happening due to context, I assume that the AA Calendar[Date] is the column you are using for the X-axis, so when you calculate the MAX and MIN value of that column you get the value for each of the x-axis values so you are always doing the following calculation:

 

DateDiff (Date - Date) -1 = (18/09 - 18/09)  - 1= 0 - 1 = -1

 

So for your calculation you are always getting -1 so the previous day you need to change your first variables to an aggregator based on the selected values of dates try the following two variables:

var max_date = MAXX(ALLSELECTED('AA Calendar'[Date]),'AA Calendar'[Date])

var min_date = MINX(ALLSELECTED('AA Calendar'[Date]),'AA Calendar'[Date])

 

This sould return expected result.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

Create the following measure

Previous 7 days =
CALCULATE (
    SUM ( 'Table'[Visits] ),
    FILTER (
        'Table',
        [Date]
            IN DATESBETWEEN ( 'AA Calendar'[Date], TODAY () - 7, TODAY () )
    )
)

The measure is automatically updated based on the current date because of the TODAY() function.

16.png

 

 

Best Regards,

Stephen 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

2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

Create the following measure

Previous 7 days =
CALCULATE (
    SUM ( 'Table'[Visits] ),
    FILTER (
        'Table',
        [Date]
            IN DATESBETWEEN ( 'AA Calendar'[Date], TODAY () - 7, TODAY () )
    )
)

The measure is automatically updated based on the current date because of the TODAY() function.

16.png

 

 

Best Regards,

Stephen Tao

 

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

MFelix
Super User
Super User

Hi @Anonymous ,

 

This is happening due to context, I assume that the AA Calendar[Date] is the column you are using for the X-axis, so when you calculate the MAX and MIN value of that column you get the value for each of the x-axis values so you are always doing the following calculation:

 

DateDiff (Date - Date) -1 = (18/09 - 18/09)  - 1= 0 - 1 = -1

 

So for your calculation you are always getting -1 so the previous day you need to change your first variables to an aggregator based on the selected values of dates try the following two variables:

var max_date = MAXX(ALLSELECTED('AA Calendar'[Date]),'AA Calendar'[Date])

var min_date = MINX(ALLSELECTED('AA Calendar'[Date]),'AA Calendar'[Date])

 

This sould return expected result.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.