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

COUNTX(currentgroup()) add column with filter

Hi all,

 

I have a table with different IDs linked to a specific Category. These IDs all have an Entry Date stored in a different (related) table.

 

I created an overview table from a different table with the GROUPBY() and COUNTX function.

I managed this with the code:

Categorization overview = GROUPBY(Categorisation,Categorisation[Category],"Count",COUNTX(CURRENTGROUP(),Categorisation[Category]))

This is the table: the green column is the result of the above code. This works OK.

 

count.JPG

 

The two columns in red are the columns I am trying to add.

 

Add column 1:

I need a column that only counts the IDs with an Entry Date > 01012019. How can I add this column? I tried to add an IF statement but when I do this I get a rondom number that is the same for each row.

 

Add column 2:

I then also need a column with the percentage of this column 1 to the initial column which contains all IDs. I want to show how much percent of the total IDs in that category has recently been created (based on the Entry Date).

 

Thanks for your help!

 

Zipke

1 ACCEPTED SOLUTION

Hi @v-lili6-msft ,

 

It is not that easy to share my relationships because it is a larger complex file. But in manged to solve the problem in the meantime! I used a different code and it works!

I created the table with only the categories and then added a Count column and a Count column for the IDs.

Table creation:

Categorisation overview = GROUPBY(Categorisation,Categorisation[Category])

Count of IDs per category:

Count = CALCULATE(
    COUNTROWS(Categorisation),
        FILTER(Categorisation,Categorisation[Category]=EARLIER([Category])
        )
)

Column 1:

New IDs count = CALCULATE(
    COUNTROWS(Categorisation),
        FILTER(Categorisation,Categorisation[Category]=EARLIER([Category])),
        FILTER(RELATEDTABLE('Entry Dates'),'Entry Dates'[Entry date]>=20181201)
        )

Thanks for your help though!

 

Regards,

Zipke

View solution in original post

6 REPLIES 6
Whibley92
Helper II
Helper II

Hello, I have a query related this - I have used the below to count the number of occurences of an id number in one column:

 

occurrences = COUNTX( FILTER( 'Specialisations', EARLIER('Specialisations'[Person Number]) = Specialisations[Person Number]),Specialisations[Person Number])

 

I want to count only those ids which have a certain course title. I'm not sure what the best way to do this is - maybe i should be using calculate?

 

i.e count occurence of person number if course title = XXX

 

 

v-lili6-msft
Community Support
Community Support

hi, @zipke 

You may try this simple way:

Step1:

Create the relationship between Categorisation table and new overview table by category column.

Step2:

Then use this formula to add new column

Column 1 = CALCULATE(COUNTA('different (related) table'[ID]),FILTER(RELATEDTABLE('different (related) table'),'different (related) table'[Entry Date]>DATE(2019,1,12)))
Column 2 = 'Categorization overview'[Column 1]/'Categorization overview'[Count]

 

Best Regards,

Lin

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

Hi @v-lili6-msft ,

 

Thanks for your response. For column 1, I do get a count, but it shows me the total on each row. It does not split up the value per category. I did create the relationship between the Categorisation table and the Entry Date table.

 

How should I tweek the code?

 

Thanks in advance

hi, @zipke 

Could you share your sample pbix file or screenshots about the relationship?

 

Best Regards,

Lin 

 

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

Hi @v-lili6-msft ,

 

It is not that easy to share my relationships because it is a larger complex file. But in manged to solve the problem in the meantime! I used a different code and it works!

I created the table with only the categories and then added a Count column and a Count column for the IDs.

Table creation:

Categorisation overview = GROUPBY(Categorisation,Categorisation[Category])

Count of IDs per category:

Count = CALCULATE(
    COUNTROWS(Categorisation),
        FILTER(Categorisation,Categorisation[Category]=EARLIER([Category])
        )
)

Column 1:

New IDs count = CALCULATE(
    COUNTROWS(Categorisation),
        FILTER(Categorisation,Categorisation[Category]=EARLIER([Category])),
        FILTER(RELATEDTABLE('Entry Dates'),'Entry Dates'[Entry date]>=20181201)
        )

Thanks for your help though!

 

Regards,

Zipke

hi, @zipke 

You're welcome.

It's pleasant that your problem has been solved, could you please mark the reply as Answered.  Smiley Very Happy

 

Best Regards,

Lin

 

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

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.