Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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
  • 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/

2 Replies

  • ValtteriN's avatar
    ValtteriN
    Icon for Community Champion rankCommunity Champion

    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/
  • Anonymous's avatar
    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))