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

Filter and sum

 

I would like to create a calculated column "MemberMonthCount for each ID" based on "ID" and "YEARMONTH"

My aim is to find the sum of those member months for a date range.

Memeber months should be calculated only for those members which belong to that particular roster month which is selected using a slicer. Also the YearMonth should lie in the date range selected in another slicer.

 

 

CapturePBI.PNG

 

2 ACCEPTED SOLUTIONS
v-sihou-msft
Employee
Employee

@bsushy

 

In this scenario, what you want to return is just a DISTINCTCOUNT() of members within the YEARMONTH range your selected. You can just create a measure like below:

 

Distinct Members =
CALCULATE ( DISTINCTCOUNT ( Table[ID] ), ALLSELECTED ( Table[YEARMONTH] ) )

Regards,

 

 

View solution in original post

In your query, right-click your YEARMONTH column and duplicate it. Then, use YEARMONTH as your list slicer and YEARMONTH - Copy as your date range slicer. Then you can create a measure like this:

 

Measure 5 = CALCULATE(DISTINCTCOUNT('Members'[YEARMONTH]),ALLEXCEPT('Members','Members'[YEARMONTH - Copy]))

 

 


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

View solution in original post

10 REPLIES 10
v-sihou-msft
Employee
Employee

@bsushy

 

In this scenario, what you want to return is just a DISTINCTCOUNT() of members within the YEARMONTH range your selected. You can just create a measure like below:

 

Distinct Members =
CALCULATE ( DISTINCTCOUNT ( Table[ID] ), ALLSELECTED ( Table[YEARMONTH] ) )

Regards,

 

 

By doing this i would just get the distinct ID's in each membermonth. But i would like to calculate in how many membermonths those Id's (from selected membermonth '201704')  have appeared in the selected range ('201705-201605')

Greg_Deckler
Super User
Super User

Seems like you could just do a SUM of MemberMonthCount but not enough information to really say. 


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

@Greg_DecklerCould you help me with the calculated column "MemberMonthCount".

How do I write it....It should also be calculated only for those ID's which are in that selected memeber month '201704'

..Then it would be easy for me to write a measure for the sum.

Is your raw data just like in the image where you have ID and YEARMONTH columns in your data table? Please confirm and if not, please post some sample raw data.

 

Please read: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 


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

@Greg_Deckler: Yes.My data has ID and Yearmonth....I need to calculate MemberMonthCount...Thank you for the promt reply.

OK, to clarify one last point, I would assume that this is a subset of the data and that the members would have a continuous membership up until the time selected in the YEARMONTH slicer (201704 in your example). So, if I am following what you are trying to do, you are trying to choose a particular YEARMONTH and for members for that particular YEARMONTH, you are trying to see how long they have been a member for the date range selected and get a sum of that value. Is that all correct?


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

Members do not have a continuous membership up until the time selected in the YEARMONTH slicer (201704 in the example).

They can be in one YEARMONTH and not be in another YEARMONTH in the date range.

 

So, if I am following what you are trying to do, you are trying to choose a particular YEARMONTH and for members for that particular YEARMONTH, you are trying to see how long they have been a member for the date range selected and get a sum of that value. Is that all correct?---This is exactly what I need.

In your query, right-click your YEARMONTH column and duplicate it. Then, use YEARMONTH as your list slicer and YEARMONTH - Copy as your date range slicer. Then you can create a measure like this:

 

Measure 5 = CALCULATE(DISTINCTCOUNT('Members'[YEARMONTH]),ALLEXCEPT('Members','Members'[YEARMONTH - Copy]))

 

 


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

Could you help me with the calculated column "MemberMonthCount".

How do I write it....It should also be calculated only for those ID's which are in that selected memeber month '201704'

..Then it would be easy for me to write a measure for the sum.

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.