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
Kudy
Helper I
Helper I

Sameperiodlastyear per category

My first post ever 🙂

Hi,
I have the following table called Transactions from an online shop:

Order ID    Item ID  Category  Date
444 applefruit1-jan-2021
555  pearfruit2-jan-2021
666 applefruit3-jan-2021
777  potatovegetable4-jan-2021
111  orangefruit1-jan-2020
222  broccolivegetable2-jan-2020
333cabbagevegetable3-jan-2020


Now I have created a slicer for Date and a matrix table.
In my matrix table, I have now two first columns below (A&B).
What I don't have is column C, which counts LY values for the date range I chose through my slicer. 

A  
Row: Category  
  B
 Values: Count Item ID  
  C
  Values: Count Item ID      (sameperiodlastyear)
Fruit31
Vegetable12


Really appreciate your help!

Br,
Kudy

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @Kudy ,

 

You could create a seperate year table.

Table 2 = DISTINCT('Table'[Date].[Year])

1.png

 

Two measure are created as

Count Item ID = IF(ISFILTERED('Table 2'[Year]),CALCULATE(COUNT('Table'[Item ID]),FILTER('Table',YEAR([Date])=SELECTEDVALUE('Table 2'[Year]))),COUNT('Table'[Item ID]))
Count Item ID(sameperiodlastyear) = IF(ISFILTERED('Table 2'[Year]), CALCULATE(COUNT('Table'[Item ID]),FILTER('Table',YEAR([Date])=SELECTEDVALUE('Table 2'[Year])-1)),COUNT('Table'[Item ID]))

2.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 @Kudy ,

 

You could create a seperate year table.

Table 2 = DISTINCT('Table'[Date].[Year])

1.png

 

Two measure are created as

Count Item ID = IF(ISFILTERED('Table 2'[Year]),CALCULATE(COUNT('Table'[Item ID]),FILTER('Table',YEAR([Date])=SELECTEDVALUE('Table 2'[Year]))),COUNT('Table'[Item ID]))
Count Item ID(sameperiodlastyear) = IF(ISFILTERED('Table 2'[Year]), CALCULATE(COUNT('Table'[Item ID]),FILTER('Table',YEAR([Date])=SELECTEDVALUE('Table 2'[Year])-1)),COUNT('Table'[Item ID]))

2.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.

 

Greg_Deckler
Super User
Super User

@Kudy There are two main ways of doing this, using TI functions like SAMEPERIODLASTYEAR or not:

To **bleep** With Time Intelligence - Microsoft Power BI Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.