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
RJMonteza
Regular Visitor

Need help with DAX to filter and count

I have a data of 3 years with 12 Periods each. I need to count the redlights categorized by YES/NO per year and period:

I have my initial DAX: 

1. CALCULATE(COUNTA(REDLIGHT[Start Time]),REDLIGHT[VALID OE ERROR (Y/N?)] IN {"YES"})
 
2. SUMX(
    VALUES(REDLIGHT[Start Time]),
    CALCULATE(
        COUNTROWS('REDLIGHT'),
        REDLIGHT[VALID OE ERROR (Y/N?)] IN {"YES"}
 
However, both DAX count the valid redlights ("YES") to all years though I stated to count per date.

Thanks!
 
8 REPLIES 8
Greg_Deckler
Community Champion
Community Champion

@RJMonteza Maybe:

Measure = COUNTROWS( FILTER( 'REDLIGHT', [VALID OE ERROR (Y/N?)] = "YES" ) ) 


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hello Greg,

 

I also need to filter the date and year. I need to count how many YES in a perod in this year.

 

Thanks!

@RJMonteza I assumed those would just be part of the visual.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Nope, I need to count all the valid redlights (YES) per month of the year. Right now, my DAX is calculating all the valid redlights for those 3 years. Example: Sum of 2021, 2022, and 2023 of PD1 = RL count. Which is not correct, I need it to look like this up to perod 12:

202120222023
PD 1 = 2PD 1 = 0PD 1 = 1
PD 2 = 1PD 2 = 2PD 2 = 0
PD 3 = 0PD 3 = 1PD 3 = 1

@RJMonteza Not sure I am completely following but you can do this:

Measure 2021 = COUNTROWS( FILTER( 'REDLIGHT', [VALID OE ERROR (Y/N?)] = "YES" && [YEAR] = "2021" ) ) 


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hmm... Can we have it apply to all years instead of filtering just 1 year, then per period, then countrows. I am seeing that there is a need to use VAR, but I'm not sure how..

@RJMonteza OK, so like this?

Measure 2021 = 
  VAR __Table = 
    SUMMARIZE(
      FILTER( 'REDLIGHT', [VALID OE ERROR (Y/N?)] = "YES" ),
      [YEAR},
      [PERIOD],
      "__Count", COUNTROWS( 'REDLIGHT' )
    )
  VAR __Result = SUMX( __Table, [__Count] )
RETURN
  __Result

Note that sample data and expected result would make this FAAARRRR more easy to figure out what you are going for here.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

I'm having this as a result:

 

RJMonteza_0-1686064445254.png

The result I need is a a single digit one up to PD 8 only, since we only have a data until PD 8. I need this to be:

 

PD 1 = 1

PD 2 = 1

PD 3 = 0

PD 4 = 1
PD 5 = 1

etc.

 

Note: The redlight table is another table from this one.

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.