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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Archenar
Regular Visitor

Comparing the same variable for two points in time from one data set

Hi Team,

 

I have a set of Data. Something like the below - the source table.

 

What I'd like to do is compare Sales and Count for Date X and Date Y. So I would have two separate sliders, one for Date X and one for Date Y. And I would return Sales for Date X and Date Y.

 

I have tried to duplicate the table below, to join to itself on Group A, Group B, and Group C. However, as it is a many to many join, it does not work well returning Sales from the primary and then secondary (the duplicate of the primary) table.

 

I feel I need to create a date table to join to. But the examples I have seen in this forum do not seem to work. I am not sure what to join this table to. If I need some DAX formula to manipulate Sales and Count.

 

I have not that much experience with DAX, except trying to get this to work, however, am willing to learn.

 

I'd love to have a chart with a bar for Sales for Date X and a separate bar with Sales for Date Y. 

 

Thanks in advance, and it seems a simple request... Apologies I cannot find an already published solution.

 

Arch,

 

MonthGroup AGroup BGroup CSalesCount
31-Jan-23SingaporeHouseOnline2341
31-Jan-23SingaporeHouseOnline4002
31-Jan-24SingaporeHouseOnline3004
31-Jan-24New ZealandHouseIn Store2202
31-May-23New ZealandBusinessIn Store1003
31-May-23New ZealandBusinessIn Store1232
31-May-23AustraliaBusinessIn Store1234
31-May-23AustraliaBusinessOnline2345
31-May-23AustraliaBusinessIn Store2353
31-Aug-23SingaporeHouseIn Store2341
31-Aug-23SingaporeBusinessOnline4002
31-Aug-23SingaporeHouseOnline3004
31-Aug-23New ZealandHouseIn Store2202
31-Aug-23New ZealandBusinessIn Store1003
31-Aug-23New ZealandBusinessIn Store1232
30-Sep-23AustraliaBusinessIn Store1234
30-Sep-23AustraliaHouseOnline2345
30-Sep-23AustraliaBusinessOnline2353

 

1 ACCEPTED SOLUTION

You need two date tables so that you can select 2 different date ranges using 2 slicers. The below can be achieved through filtering on two different date columns (while it might be possible for one date column and one date table, this isn't best practice so using 2 date tables is best)

vicky__0-1717721775251.png

I'm unsure what you mean by joining? if you mean creating a relationship, then yes you will need to create an inactive relationship between the two calendar and also one (active) relationship between one of the calendar tables and your month column. 

 

You can pretty much just copy the code from the article i linked earlier, and change the name.

i.e for sales:

Sales = SUM(Table[Sales]) // this will take the date range selected in the table with the active relationship

and 

Comparison Sales :=
CALCULATE (
    [Sales],
    ALL ( 'Calendar' ),
    USERELATIONSHIP ( 'Calendar'[Date], 'Other Calendar'[Date] )
) // this will take the date range selected in the other slicer

View solution in original post

5 REPLIES 5
Archenar
Regular Visitor

Thanks vicky_. 

 

I've used that exact example (plus others) and I am missing something... I feel the article has two data sources, and also two date tables. I am not sure why two date tables are required? I can create a date table (i.e. as below). But I am not sure it needs joining (I assume not as a lot of date tables just sit there alone) and how it relates to the date field in my data?

Date = ADDCOLUMNS(CALENDARAUTO(),"Year",YEAR([Date]),"Month",MONTH([Date]),"MonthName",FORMAT([Date],"MMMM"))

 I'm missing something... Just not sure what the link is...

 

Thanks for looking.

Arch

You need two date tables so that you can select 2 different date ranges using 2 slicers. The below can be achieved through filtering on two different date columns (while it might be possible for one date column and one date table, this isn't best practice so using 2 date tables is best)

vicky__0-1717721775251.png

I'm unsure what you mean by joining? if you mean creating a relationship, then yes you will need to create an inactive relationship between the two calendar and also one (active) relationship between one of the calendar tables and your month column. 

 

You can pretty much just copy the code from the article i linked earlier, and change the name.

i.e for sales:

Sales = SUM(Table[Sales]) // this will take the date range selected in the table with the active relationship

and 

Comparison Sales :=
CALCULATE (
    [Sales],
    ALL ( 'Calendar' ),
    USERELATIONSHIP ( 'Calendar'[Date], 'Other Calendar'[Date] )
) // this will take the date range selected in the other slicer

Actually - by referencing the [Sales] with my source table as in sum('Source'[required column]) it seems to work... Let me muck around with it a bit more, and if it works I'll accept your solution 🙂

Comparison Sales :=
CALCULATE (
    [Sales],
    ALL ( 'Calendar' ),
    USERELATIONSHIP ( 'Calendar'[Date], 'Other Calendar'[Date] )
) // this will take the date range selected in the other slicer

I'm still persisting with the solution you have aided me with...

 

For the above - does the [Sales] column not need a reference to the source table it comes from? And why is ALL ( 'Calendar' ) used? 


I am very new to this - so thanks for your help. I am normally good at 'stealing' code and manipulating it for my needs. Just lack an understanding.

vicky_
Super User
Super User

Have a read of this article: https://www.sqlbi.com/articles/filtering-and-comparing-different-time-periods-with-power-bi/

best practice is to create a disconnected date table so that you can select two separate ranges without the filters interfering with each other.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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