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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
LuukP
Helper I
Helper I

One date slicer, two table visuals showing different years

Hello everyone,

 

Here is a (hopefully) simple problem that I've been struggling with on various occasions. I'll use a simple example to illustrate what I mean:

 

Suppose I have a table with the following columns:
Book Title | Author | Received Date

 

Using a relative Date Slicer (using a separate Dates table), I will have one table visual showing all books received in the last 3 months. No problem.

 

Now, I'd like to have a second table visual showing all books received in the same period last year.

 

How do I do that?

 

Thank you in advance!

1 ACCEPTED SOLUTION

Hi @LuukP ,

 

In this case you need to do for example a count rows and this depending on the columns you use will return for example 1 (if you selected a specific book), or 10 (if you aggregate by author or date) then you can use that value to filter your list.

 

I created the following measure:

Books previou year = 

CALCULATE (
   COUNTROWS(Books),
    SAMEPERIODLASTYEAR ( 'Calendar'[Date] )
)

 

See result below:

MFelix_0-1678472509399.png

Has you can see I'm getting the books for current year and previous year.

 

If you need you can change the metric to give you a list of books or dates depending on the aggregation.

 

Making a small change I have  created one for the books and use it in a list:

Books previou year = 

CALCULATE (
   CONCATENATEX(Books,Books[Book Title], ","),
    SAMEPERIODLASTYEAR ( 'Calendar'[Date] )
)

MFelix_1-1678472757727.png

You just need to pick up one value to get the filter made for you data.

 

 

 


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

5 REPLIES 5
LuukP
Helper I
Helper I

Hi Miguel,

 

Thanks for your response.  The issue is that there is no value that I am trying to calculate.  There is no SalesAmount or similar value, just a list of records that have a date field.  So, can I do this without using a CALCULATE function?

 

LuukP

Hi @LuukP ,

 

In this case you need to do for example a count rows and this depending on the columns you use will return for example 1 (if you selected a specific book), or 10 (if you aggregate by author or date) then you can use that value to filter your list.

 

I created the following measure:

Books previou year = 

CALCULATE (
   COUNTROWS(Books),
    SAMEPERIODLASTYEAR ( 'Calendar'[Date] )
)

 

See result below:

MFelix_0-1678472509399.png

Has you can see I'm getting the books for current year and previous year.

 

If you need you can change the metric to give you a list of books or dates depending on the aggregation.

 

Making a small change I have  created one for the books and use it in a list:

Books previou year = 

CALCULATE (
   CONCATENATEX(Books,Books[Book Title], ","),
    SAMEPERIODLASTYEAR ( 'Calendar'[Date] )
)

MFelix_1-1678472757727.png

You just need to pick up one value to get the filter made for you data.

 

 

 


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



Thank you for the solution.  I should note that I had to set up a one-to-many relationship between my date table and my books table - then it worked.

@LuukP ,

 

Forgot to mention that, I always assume that the relationship is active.


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



MFelix
Super User
Super User

Hi @LuukP ,

 

For this you need to create a measure that gets the values for the same period last year something similar to 

Previous Year =

CALCULATE (
    [Sales Amount],
    SAMEPERIODLASTYEAR ( 'Date'[Date] )
)

 

This is one of the options check the links below with the explanation of this calculations and some similar.

 

https://www.sqlbi.com/articles/compare-equivalent-periods-in-dax/

https://www.sqlbi.com/tv/dateadd-sameperiodlastyear-dax-guide/

 


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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.