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
Anonymous
Not applicable

Using Measure to Compare Current Period to Previous Period

Hi Everyone,

I am currently using the measure below to compare the current period and the previous period, but since the measure is going back by number of days I am running into a problem. For example, June 1-June 30th is the current period. The previous period will show May 1st to May 30th, but leave out May 31st because the measure goes back by the number of days, not by month.

Can this measure be modified to show the previous period as a complete month?

 

The reason why I choose to use this measure over an alternative measure is that I can easily change the filter on the page to show month vs month, quarter vs quarter, and year vs year, and all the visuals will update to reflect those changes. I can make measures to show those time ranges, but I would rather not if I can get this measure to work properly.

TIA!

Visitors for Previous Period = 
VAR PeriodEnd = FIRSTDATE('Date'[Date])-1
VAR PeriodStart = 
PeriodEnd - 
DATEDIFF(
    FIRSTDATE('Date'[Date]),
    LASTDATE('Date'[Date]),
    DAY
)
VAR Result = 
CALCULATE(
    [Sum of Sessions],
    DATESBETWEEN('Date'[Date],
    PeriodStart,PeriodEnd
    )
)
Return
Result

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi Everyone,

 

Here is the solution that I have found to work. I hope someone finds this useful. I will give credit to the freelancer who came up with this at the end of the post.

End Result:

You will have one slicer for the current period and one slicer for the previous period. You can compare any range of dates to one another by selecting your date range in the corresponding slicer. In the photo below the current period slicer is showing 6/1/2021-6/30/2021 and the previous period slicer is showing 5/1/2021-5/31/2021. The light blue line is showing the current period and the dark blue line is showing the previous period in the visuals.

Previous Period Comparison Solution.PNG

 

Step 1:

Create a new measure called "Previous Date Selector" and use your date table as the parameter value.

Previous Period Comparison Step 1.PNG

 

Step 2:

Create an inactive one too many relationship between your "Previous Date Selector" and regular date table.

Previous Period Comparison Step 2.PNG

 

Step 3:

 

Create a slicer from your standard date table and name it "current period" and create a slicer from your "previous date selector" and name it "previous period."

 

Previous Period Comparison .90.PNG

 

Previous Period Comparison .91.PNG

 

Step 4:

Create a measure with the following dax. In this case, I am comparing total sessions in the current period to total sessions in the previous period so I am using the "total sessions" value.

 

Previous Period Comparison Step 3.PNG

 

Step 5

Add your two values to the visual you would like to use to compare the current period to the previous period. In this case, I am comparing total sessions from google analytics so I have a measure for "total sessions", which is synched to the current period slicer and a measure for "total visitors for previous period", which is synched to the previous period slicer.

Previous Period Comparison Step 5.PNG

 

I hope this helps someone! 

 

Freelancer: andystepas | Profile | Fiverr

 

View solution in original post

10 REPLIES 10
Ashish_Mathur
Super User
Super User

Hi,

This should work

Visitors for previous period = calculate([sum of sessions],previousmonth('Date'[Date]))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@Anonymous if this works for you good but not sure I will go that route, it means the user always has to select a value in both the slicers to compare. Not sure if it is a great UX but if it solves your needs, well done.

 

Cheers,

P



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi Everyone,

 

Here is the solution that I have found to work. I hope someone finds this useful. I will give credit to the freelancer who came up with this at the end of the post.

End Result:

You will have one slicer for the current period and one slicer for the previous period. You can compare any range of dates to one another by selecting your date range in the corresponding slicer. In the photo below the current period slicer is showing 6/1/2021-6/30/2021 and the previous period slicer is showing 5/1/2021-5/31/2021. The light blue line is showing the current period and the dark blue line is showing the previous period in the visuals.

Previous Period Comparison Solution.PNG

 

Step 1:

Create a new measure called "Previous Date Selector" and use your date table as the parameter value.

Previous Period Comparison Step 1.PNG

 

Step 2:

Create an inactive one too many relationship between your "Previous Date Selector" and regular date table.

Previous Period Comparison Step 2.PNG

 

Step 3:

 

Create a slicer from your standard date table and name it "current period" and create a slicer from your "previous date selector" and name it "previous period."

 

Previous Period Comparison .90.PNG

 

Previous Period Comparison .91.PNG

 

Step 4:

Create a measure with the following dax. In this case, I am comparing total sessions in the current period to total sessions in the previous period so I am using the "total sessions" value.

 

Previous Period Comparison Step 3.PNG

 

Step 5

Add your two values to the visual you would like to use to compare the current period to the previous period. In this case, I am comparing total sessions from google analytics so I have a measure for "total sessions", which is synched to the current period slicer and a measure for "total visitors for previous period", which is synched to the previous period slicer.

Previous Period Comparison Step 5.PNG

 

I hope this helps someone! 

 

Freelancer: andystepas | Profile | Fiverr

 

Hi,

this is exactly what I am trying to achieve but I am having an issue with step 1: "Create a new measure called "Previous Date Selector" and use your date table as the parameter value."

My date field doesn't show up as a date in the parameter and it looks like I cannot use it for anything.

This is an old post but I hope someone can help me figure out what might be wrong.

Thanks!

parry2k
Super User
Super User

@Anonymous there is no point beating the bushes, seems like you are again overcomplicating the calculations. Anyhow, I hope someone can help and walk you thru. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Anonymous there is no concept of almost perfectly, it is working or not, you have to use calculation group, maybe with 4 calculation items:

 

MoM

QoQ

YoQ

Custom

 

The top 3 are self-explanatory, and in the 4th one, use the range from date slicer and then do the comparison for the same period as you are doing now. 

 

There are TONS of solutions around this and what I suggested above, I have used more than 100 times, not sure if you can take it from here or not.

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k , 

I am not opposed to using those time intelligence calculations, but the DAX expression that I have posted provides more flexibility because you can compare any period to the exact same time range over the previous period by adjusting the slicer. It is very convenient and very useful for reports that need to be regularly changed to compare unique time periods. I have illustrated the issue that is still persisting below. You will see that the previous period is showing 5/1/2021 - 5/30/2021, but it should show 5/1/2021-5/31/2021. I am still wondering if there's a way to modify this formula so the previous period shows the entire month, instead of just showing the number of days that are in the current period. 

 

example.PNG

parry2k
Super User
Super User

@Anonymous I think you are over-engineering the problem. There are way too many solution available to achieve MoM/QoQ/YoY based on the slicer selection, like calculation groups or you can use Row Based time intelligence by following this blog post  Row-based Time Intelligence - Phil Seamark on DAX

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k,

What do you think about the solution above?

If you think it can be useful please consider accepting it as a solution.

 

Thank you,

Joshua Cortigiano

Anonymous
Not applicable

Hi @parry2k ,

I have considered creating measures for a monthly, quarterly, and yearly comparison, but the problem I foresee with this method is when management says they want to see a quarterly comparison instead of a monthly comparison, all the measures will have to be switched out on the visual to show the new time comparison. I would like to have the ability to specify a date range and then show the previous period for that specific date range. This will make the entire report dynamic and eliminate the need for a measure for each time range. The measure above works almost perfectly, but the current period and previous period are compared by days, so if there are 30 days in one month and 31 days in another month, one of the months will either be missing a day or have an extra day. I am wondering if you have a suggestion on how to turn this measure into a monthly comparison.

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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.