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
Anonymous
Not applicable

Count with two filters

Hi 

 

@ValtteriN 

 

I want to count if the Production value >0 and filter with the selected month. I wrote a code like below however it counts wrong. (counts 11 however it should be 12)

 

RunningLines =
var month2 = MONTH(PowerBI[Month]) return

CALCULATE(
    COUNT(PowerBI[Production]),FILTER('PowerBI','PowerBI'[Production]>0 && 'PowerBI'[Month]=month2)
//CALCULATE(COUNTROWS((PowerBI)),FILTER(VALUES(PowerBI),PowerBI[Month]=month2),FILTER(VALUES(PowerBI),PowerBI[Production]>0))
)
 
Machines Production Direct kWh Direct m3 Date Air kW/h Month Other kWh RunningLines
A54.117.48067.32458000Ocak 20216.66011502411
A42.590.616255.248376000Ocak 202143.17411502411
A31.434.62039.58875000Ocak 20218.61211502411
A24.141.60081.594172000Ocak 202119.75011502411
A16.923.81499.737200000Ocak 202122.96511502411
P11.157.356127.054211000Ocak 202124.22811502411
D151.447.10698.02495000Ocak 202110.90811502411
D141.629.750108.420192000Ocak 202122.04611502411
D121.248.672119.557207000Ocak 202123.76911502411
D114.938.80050.769120000Ocak 202113.77911502411
D6000Ocak 2021011502411
D52.417.92662.466115000Ocak 202113.20511502411
D41.667.06226.12468000Ocak 20217.80811502411
1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

Try this: 

RunningLines = var _month = PowerBI[Month] return

COUNTROWS(FILTER(PowerBI,PowerBI[Production]>0&&PowerBI[Month]=_month),ALL(PowerBI))

Also by including MAX here this will also work as a measure:


RunningLines = var _month = MAX(PowerBI[Month]) return

COUNTROWS(FILTER(PowerBI,PowerBI[Production]>0&&PowerBI[Month]=_month),ALL(PowerBI))

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi ValtterİN

 

I copied two of the code and ALL(PowerBI) showed errors I just deleted it and it works.

 

thank you a lot

 

RunningLines =
var _month = PowerBI[Month] return
COUNTROWS(FILTER(PowerBI,PowerBI[Production]>0&&PowerBI[Month]=_month))
ValtteriN
Super User
Super User

Hi,

Try this: 

RunningLines = var _month = PowerBI[Month] return

COUNTROWS(FILTER(PowerBI,PowerBI[Production]>0&&PowerBI[Month]=_month),ALL(PowerBI))

Also by including MAX here this will also work as a measure:


RunningLines = var _month = MAX(PowerBI[Month]) return

COUNTROWS(FILTER(PowerBI,PowerBI[Production]>0&&PowerBI[Month]=_month),ALL(PowerBI))

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/




Did I answer your question? Mark my post as a solution!

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.

Top Solution Authors