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
m_richardson
Frequent Visitor

Measure: Count the number of distinct items in one time period that are in the previous.

I'm displaying some data that details the number of items for which there was a transaction on a monthly basis.  So, for the chart displayed below each bar is the number of distinct items in inventory that sold during each quarter.

m_richardson_0-1670247090354.png

The data above comes from a calculated measure that looks something like this:

 

Count items= DISTINCTCOUNT(Items[Item ID])
 

What I'd like to be able to do is to identify on a quarterly basis how many items in that quarter had also transacted the quarter prior.  What would be the best way of achieving this?

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

Hi , @m_richardson 

According to your description, you want to calculate the "Count the number of distinct items in one time period that are in the previous". Right?

Here are the steps you can refer to :

(1)This is my test data:

vyueyunzhmsft_0-1670295947985.png

(2)I create a calendar date table ,like this:

Date = ADDCOLUMNS( 
CALENDAR(Date(2021,1,1),Date(2022,12,31)),
"year", YEAR ( [Date] ),
"Quarter","Q" & ROUNDUP(MONTH([Date])/3,0),
"Year_Quarter", YEAR ( [Date] )*100+ ROUNDUP(MONTH([Date])/3,0)
)

vyueyunzhmsft_1-1670296121806.png

 

(3)Then we can create a measure like this:

Measure = 
var _cur_Quarter = MAX('Date'[Year_Quarter])
var _previoud_Quarter =MAXX( FILTER(ALLSELECTED('Date') , 'Date'[Year_Quarter]<_cur_Quarter) , [Year_Quarter])
var _cur_Quarter_item_ID =VALUES('Item'[Item ID])
var _previoud_Quarter_item_ID = CALCULATETABLE( VALUES('Item'[Item ID]) , FILTER(ALLSELECTED('Date'),'Date'[Year_Quarter]=_previoud_Quarter))
var _inter = INTERSECT(_cur_Quarter_item_ID,_previoud_Quarter_item_ID)
return
COUNTROWS(_inter)

(4)Then we can mrrt your need , the result is as follows:

vyueyunzhmsft_2-1670296790092.png

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

3 REPLIES 3
v-yueyunzh-msft
Community Support
Community Support

Hi , @m_richardson 

According to your description, you want to calculate the "Count the number of distinct items in one time period that are in the previous". Right?

Here are the steps you can refer to :

(1)This is my test data:

vyueyunzhmsft_0-1670295947985.png

(2)I create a calendar date table ,like this:

Date = ADDCOLUMNS( 
CALENDAR(Date(2021,1,1),Date(2022,12,31)),
"year", YEAR ( [Date] ),
"Quarter","Q" & ROUNDUP(MONTH([Date])/3,0),
"Year_Quarter", YEAR ( [Date] )*100+ ROUNDUP(MONTH([Date])/3,0)
)

vyueyunzhmsft_1-1670296121806.png

 

(3)Then we can create a measure like this:

Measure = 
var _cur_Quarter = MAX('Date'[Year_Quarter])
var _previoud_Quarter =MAXX( FILTER(ALLSELECTED('Date') , 'Date'[Year_Quarter]<_cur_Quarter) , [Year_Quarter])
var _cur_Quarter_item_ID =VALUES('Item'[Item ID])
var _previoud_Quarter_item_ID = CALCULATETABLE( VALUES('Item'[Item ID]) , FILTER(ALLSELECTED('Date'),'Date'[Year_Quarter]=_previoud_Quarter))
var _inter = INTERSECT(_cur_Quarter_item_ID,_previoud_Quarter_item_ID)
return
COUNTROWS(_inter)

(4)Then we can mrrt your need , the result is as follows:

vyueyunzhmsft_2-1670296790092.png

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

 

 

djurecicK2
Super User
Super User

Hi @m_richardson ,

 Assuming you have a date table, you can you the PREVIOUSQUARTER function: 

https://learn.microsoft.com/en-us/dax/previousquarter-function-dax

 

Please accept as solution if this answers the question- thanks!

 

That won't give me what I want.

 

Let's say (for example) that in Q1 I had the following list of IDs of items that had sold:

 

10,11,12,13,14

 

And in Q2, this was the list:  10,13,14,22

 

Then what I'd want is for a way of telling me that in Q2 there were 3 IDs that had appeared in the previous quarter. 

 

Hope that makes sense.

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.