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
JIGAR
Resolver IV
Resolver IV

Find counts based on the very first transaction (MIN Transaction Date)

Hello Experts,

I am trying to implement a logic to calculate the distinct count of members on each state based on their first transaction within a selected date range.

I have provided the sample data and example of what I am trying to achieve.Here is the sample data.

 

Member KeyTransaction DateStateMultiplier
User101/04/21New Join1
User102/06/21Cancel-1
User102/08/21Reinstate1
User201/10/21New Join1
User202/10/21Cancel-1
User301/04/20New Join1
User301/05/20Cancel-1
User301/12/20Reinstate1
User402/26/20New Join1
User502/22/20New Join1
User604/25/20New Join1
User604/29/20Cancel-1
User605/02/20Reinstate1
User702/10/21Reinstate1
User 802/25/20Reinstate1


Example :

Measure 1

If user selects a date range from Jan 1 2021 to Feb 28 2021

User 1 has two states within this date range where multiplier = 1

i.e. New Join and Reinstate on 1/4/21 and 2/8/21 respectively

I want to count User 1 for its first transaction within that period

Similarly for other users. Logic should be around first transaction where multiplier =1 in the selected time frame.

Final Result that I am looking for Measure 1 is :

 

New Join - 2 (User 1, User 2)

Cancel - 0

Reinstate - 1 (User 7)


Measure 2

Another measure should count the same thing but for same period last year.

So for date range from Jan 1 2020 to Feb 28 2020

Final result for Measure 2 should be

 

New Join - 3 ( User 3, User 4, User 5)

Reinstate - 1 (User8)

Cancel - 0


This count should adjust itself based on the selected time period.


There is one more case where if a user selects date range from Jan 1 2020 to December 31 2021 then how can we have these measures work for individual year when used on a matrix visual ?

 

For e.g : Between Jan 1 2020 and Dec 31 2021

Matrix should show something like this

 

JIGAR_0-1620180412626.png

 

Can someone please help me with this logic ? I would really appreciate the help.

 

Thank you

 

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@JIGAR 

 

Measure 1 = CALCULATE(COUNT('Table'[State]),FILTER('Table',[Transaction Date]=CALCULATE(MIN([Transaction Date]),ALLEXCEPT('Table','Table'[Member Key]))))

V-pazhen-msft_1-1620376371920.png

 

Measure 2 = CALCULATE(COUNT('Table'[State]),FILTER('Table',[Transaction Date]=CALCULATE(MAX([Transaction Date]),ALLEXCEPT('Table','Table'[Member Key]))))
V-pazhen-msft_2-1620376387185.png

 

Please check the pbix for detail, measure 1 is on page 1, measure 2 is on page 2.

 


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
V-pazhen-msft
Community Support
Community Support

@JIGAR 

 

Measure 1 = CALCULATE(COUNT('Table'[State]),FILTER('Table',[Transaction Date]=CALCULATE(MIN([Transaction Date]),ALLEXCEPT('Table','Table'[Member Key]))))

V-pazhen-msft_1-1620376371920.png

 

Measure 2 = CALCULATE(COUNT('Table'[State]),FILTER('Table',[Transaction Date]=CALCULATE(MAX([Transaction Date]),ALLEXCEPT('Table','Table'[Member Key]))))
V-pazhen-msft_2-1620376387185.png

 

Please check the pbix for detail, measure 1 is on page 1, measure 2 is on page 2.

 


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@JIGAR , with help from a date table

 

Measure1 =
VAR __id = MAX ('Table'[Member Key] )
VAR __date = CALCULATE ( MAX('Table'[Transaction Date] ), ALLSELECTED ('Table' ), 'Table'[Member Key] = __id )
CALCULATE ( Count ('Table'[Transaction Date] ), VALUES ('Table'[Member Key] ),'Table'[Member Key] = __id,'Table'[Transaction Date] = __date )

 

 

Measure2 =
VAR __id = MAX ('Table'[Member Key] )
VAR __date = CALCULATE ( MAX('Table'[Transaction Date] ), ALLSELECTED ('Table' ), 'Table'[Member Key] = __id, sameperiodlastyear(Date[DATE) )
CALCULATE ( Count ('Table'[Transaction Date] ), VALUES ('Table'[Member Key] ),'Table'[Member Key] = __id,'Table'[Transaction Date] = __date, sameperiodlastyear(Date[DATE) )

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

@amitchandak :

 

Thank you for your quick response.

 

These measures does not seem to be giving me the correct results. Measure 1 is showing values which is not exactly the way its expected.

 

JIGAR_0-1620185692065.png

Measure 1 should have give the values as 

 

New Join - 2 (User 1, User 2)

Cancel - 0

Reinstate - 1 (User 7)

 

Measure 2 shows values (incorrect result) only when the date range is selected for year 2022. However, there is no 2022 data in the table. 

 

Thank you

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.