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
android1
Post Patron
Post Patron

Count Columns that don't contain zero

Hi,

 

Trying to count the number of weeks which have been invoiced.

In attached image, Week numbers are at the top (Wk 3 - 21).

 

The values (14.00, 17.50 etc are the column [Visits_NoHrs])

 

Trying this fromula ->

 

Num Invoiced Weeks = CALCULATE(COUNTA(vw_PivotVisitsInvoiced[Visits_NoHrs]),vw_PivotVisitsInvoiced[Visits_NoHrs] <> 0) but getting 1 for the example in attached. (expect 😎

 

Regards,

 

 

Invoiced Hrs.jpgGerry

12 REPLIES 12
vanessafvg
Super User
Super User

@android1

 

wouldn't > 0 work better then <> 0?   i am assuming its a number?

 

your example doesn't make sense to me, what should be 1 or shouldn't be?

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Hi vanessafvg,

 

>0 returns the same. Num Invoiced weeks should be 8 as there are 8 times (weeks) where [Visits_NoHrs] is not zero.

I want to count the weeks where [Visits_NoHrs] <> 0.

 

I get 1 rather than 8.

 

Num Inv Wks 2.jpg 

 

 

 

 

@android1

what does your data look like? can you post a screenshot?

 

what if you tried something liek this 

Num Invoiced Weeks = CALCULATE(countrows(vw_PivotVisitsInvoiced), not(isblank(vw_PivotVisitsInvoiced[Visits_NoHrs]))

 

is the data blank or 0?

 

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Hi,

 

Data is blank. 

 

Result using your formula returning the same as mine.

 

Num Inv Wk.jpg

@android1

 

 

what is your data type on no of hours?   is the row you posted below an example of what your date looks like in the tables at a detailed level?

 

 what about, noofrows = calculate(countrows(vw_PivotVisitsInvoiced), vw_PivotVisitsInvoiced[Visits_NoHrs] > 0)

 

you need to provide more information otherrwise it will be very difficult to provide you with help based on the information  you have given.  It seems to me either the data type is not as expecvted or i am nto seeing the actually data as it is in the table. as a detail level.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




[Visits_NoHrs] is Decimal Number, Format: General

NoHrs Data Type.jpg

 

I have the correct invoiced hrs for each week.

Some weeks have blank Invoiced Hrs & some have value. So what I'm trying to do is count the weeks that 

have a value ie invoiced hrs not equal to blank.

@android1  what i am asking you though is [Visits_NoHrs] a measure  you created or is it in your base data

 

 

maybe something like this would work

 

calculate (countrows(table), filter (table,  sum([Visits_NoHrs]) > 0))





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Sorry, it's a column (not a calculated created by me) It came staright from the Database.

 

No luck with that either (Num Invoiced Weeks = calculate (countrows(vw_PivotVisitsInvoiced), filter (vw_PivotVisitsInvoiced,  sum([Visits_NoHrs]) > 0)))

@android1

 

can you not post a picture of your data in the table?  i.e a screenshot of the actual table (not the results in a visual) of vw_PivotVisitsInvoiced

 

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Yeah but there are loads of columns in the DB.

 

DB Data.jpg

Maybe I'll state exactly what 'm trying to do.

 

New employees start working at any week of the year.

 

E.g

 

I have a worker who starts in week 10. They generate [Visits_NoHrs] (column directly from DB) from week 10 onwards.

Say they are off in Week 15 (so no [Visits_NoHrs] generated in Week 15). Back in Wk 16

& work Wk 17, 18, 19 ,20. In Total they have hours in 10 weeks.  I want to count these weeks.

So below I would have 8 as they generated [Visits_NoHrs] in 8 weeks.

 

Invoiced Hrs week.jpg

 

I have this calculated column - Week = WEEKNUM([Visits_Date],21) which returns the Week of the year.

@android1

 

thanks for the info.  you should be able to slice the data any which way so even with the week num, your measure should work.

 

i have created a similar scenario and this definitely works.  what are you getting with this?    There is obviously something else going on if the below doesn't work.

 

I am working on the premise here that 

vw_PivotVisitsInvoiced[Visits_NoHrs] is a decimal

 

all rows countrows(vw_PivotVisitsInvoiced)   what do you get back with this?

 

the measure as previously stated should work when you do this

 

no of rows  with hours= calculate(countrows(vw_PivotVisitsInvoiced), vw_PivotVisitsInvoiced[Visits_NoHrs] > 0)

 

if it doesn't there is something else in the data going on?  

 

eg.

 

this is the data i created

Capture.PNG

 

Capture.PNG

 

this works perfectly my measure here is

Rows > 0 = CALCULATE(COUNTROWS(Apartments),Apartments[Hours] > 0)

 

so i am not understanding why your data is not calculating properly.  You might need to dig a big deeper into the data.  





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




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.