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

count total occurrences with filter by category

Id like to create a measure or calculated column that calculates the total occuerrence of  early for each item. For example, in the table below "Item A" would have a value of 2 because "early" appears two times with "Item A". "Item B" would have a value of 0 because early does not apply. "Item C" will have 3 because early appears three times

 

 

SalesOrder #  Salesorderline#  Create Date   Invoice Date             Item    Segment                     Site                   Status   
10011/1/20241/6/2024AfrontBank Early
10022/1/20242/6/2024AfrontSchoolEarly
10111/2/20241/7/2024AbackKitchenLate
10122/2/20242/7/2024BsideParkLate
10213/1/20243/6/2024CbackHouseEarly
10224/1/20244/6/2024CfrontStoreEarly
10235/1/20245/6/2024CminMallEarly
10312/1/20242/6/2024DmaxStoreEarly

 

 

Desired output

 

 

 

SalesOrder #Salesorderline#Create Date               Invoice DateItem   Segment        Site      Status       count of early               
10011/1/20241/6/2024AfrontBank Early2
10022/1/20242/6/2024AfrontSchoolEarly2
10111/2/20241/7/2024AbackKitchenLate2
10122/2/20242/7/2024BsideParkLate 
10213/1/20243/6/2024CbackHouseEarly3
10224/1/20244/6/2024CfrontStoreEarly3
10235/1/20245/6/2024CminMallEarly3
10312/1/20242/6/2024DmaxStoreEarly1
1 ACCEPTED SOLUTION

@dwhittaker1 

Add an additional filter to your calculated column as follows, I assume you need the year from the Creation Date. you can change it to a different column as well.

Early Count = 
CALCULATE(
    COUNTROWS(Table01),
    ALLEXCEPT( Table01 , Table01[Item    ]),
    Table01[Status   ] = "Early",
      YEAR( Table01[Create Date   ]) = 2024
)

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

Column = CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Item    ]=EARLIER(Data[Item    ])&&Data[Status   ]="Early"))

Hope this helps.

Ashish_Mathur_0-1711772166767.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

  • @Ashish_Mathur  thank you for your help, how would I add a filter to your measure that returns only returns results for the year 2024
Fowmy
Super User
Super User

@dwhittaker1 

Add this calculated column:

Early Count = 
CALCULATE(
    COUNTROWS(Table01),
    ALLEXCEPT( Table01 , Table01[Item]),
    Table01[Status] = "Early"
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

  • @Fowmy thank you for your help, how would I add a filter to your measure that returns only returns results for the year 2024

@dwhittaker1 

Add an additional filter to your calculated column as follows, I assume you need the year from the Creation Date. you can change it to a different column as well.

Early Count = 
CALCULATE(
    COUNTROWS(Table01),
    ALLEXCEPT( Table01 , Table01[Item    ]),
    Table01[Status   ] = "Early",
      YEAR( Table01[Create Date   ]) = 2024
)

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.