Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
PPalkowski
Helper II
Helper II

Counting months that have a sum greater than zero

I have this table

AnimalFed
Lion2/2/2020
Lion2/5/2020
Bear 
Dog2/2/2020
Cat 
Bird1/30/2020
Bird2/2/2020
Deer1/30/2020
Monkey 
Monkey 
Cat 
Bear 
Beaver1/2/2020
Beaver1/3/2020
Beaver2/2/2020
Moose 

and this visual

AnimalJanuaryFebruaryTotal
Bear000
Beaver213
Bird112
Cat000
Deer101
Dog011
Lion022
Monkey000
Moose000

what I need is if an animal was fed at least once that month, signify that with an x and count the x's as shown

AnimalJanuaryFebruaryCount
Bear000
Beaverxx2
Birdxx2
Cat000
Deerx01
Dog0x1
Lion0x1
Monkey000
Moose000

 

How can I do this?

 

1 ACCEPTED SOLUTION

I have everything I need, YOU have been an AWESOME resource!!

Have a wonderful weekend!

 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Sorry I missed the detail where the total only needs to reflect the distinct months
 
AnimalFed = 
switch(
true(),
ISFILTERED(Dates[MonthName]),if (ISBLANK(count(Animals[Fed])),0,"x"),
COUNTROWS( groupby ( Animals, Animals[Animal], Dates[MonthName] ) )
)

the countrows should get the required results. It creates a table per animal per month and then counts the rows. 

 

Jan 

I get an error

image.png

 

Anonymous
Not applicable

Ok, not having a date table, you need to create a Calculated Column in your data table:

 

MonthColumn = month('Data'[Fed])
 
the measure will then be: 
 
AnimalFed = 
switch(
true(),
ISFILTERED(Data[MonthName]),if (ISBLANK(count(Data[Fed])),0,"x"),
COUNTROWS( groupby ( Data, Data[Animal], Data[MonthColumn] ) )
)

Jan 

if this is a solution for you, don't forget to mark it as such. thanks

I have everything I need, YOU have been an AWESOME resource!!

Have a wonderful weekend!

 

Anonymous
Not applicable

Hi @PPalkowski ,

 

You can use something like this: 

2020-02-12 22_29_59-20200212 - Power BI Desktop.png

Assumming you have a date table somewhere. 

 

AnimalFed = 
switch(
true(),
ISFILTERED(Dates[MonthName]),if (ISBLANK(count(Animals[Fed])),0,"x"),
count(Animals[Fed])
)

 

Hope this helps, 

 

Jan

 

 if this is a solution for you, don't forget to mark it as such. thanks

I don't have a date table, all I have for dates are in the fed column

AnimalFed
Lion2/2/2020
Lion2/5/2020
Bear 
Dog2/2/2020
Cat 
Bird1/30/2020
Bird2/2/2020
Deer1/30/2020
Monkey 
Monkey 
Cat 
Bear 
Beaver1/2/2020
Beaver1/3/2020
Beaver2/2/2020
Moose

 

 

I created one, names Dates

MONTH
January
February
March
April
May
June
July
August
September
October
November
December

 

It's getting there, but the dates are out of order and not the matrix isn't calcualting correctly, The Lion was fed 2 times in Februaury, so Februaury would get and X, and the total would be 1, it shows an X in every month and a total of 2

 
 

image.png

 

I have the dates all sorted, 

 

your formula worked perfectly

 

AnimalFed = 
switch(
true(),
ISFILTERED(Data[Fed].[Month]),if (ISBLANK(count(Data[Fed])),0,"x"),
count(Data[Fed]) 
) 

 

All I need are 'working' totals and I am good.

image.png

 

even If I put a 1 in the formula, instead of an x

It's still not calculating correctly

image.png

 

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.