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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
EmiliaB_123
Helper II
Helper II

DAX Function assistance

Hello everyone,

I am struggling with a dax function. I have a column with zeros and ones as the column content, I need to count the zeros and the ones for a certain time period. With which dax formulas can this be done? I wanted to first count the zeros for the last 12 months and then count all positions for the last 12 months and then devide them to calculate a percentage value as a result.

 

Thanks for the support on this. 

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @EmiliaB_123 ,

 

you would create a measure for the zeros like this one:

Zeros =
CALCULATE(
    COUNTROWS(myTable)
    myTable[ColumnWithZeroValues] = 0
)

 

And a similar for the ones and a normal COUNTROWS without the filter for all values. Then you can use all of the measures in the selected time period and you get your result.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

9 REPLIES 9
selimovd
Super User
Super User

Hey @EmiliaB_123 ,

 

you would create a measure for the zeros like this one:

Zeros =
CALCULATE(
    COUNTROWS(myTable)
    myTable[ColumnWithZeroValues] = 0
)

 

And a similar for the ones and a normal COUNTROWS without the filter for all values. Then you can use all of the measures in the selected time period and you get your result.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

HI @selimovd 

thanks for the quick reply - this works very good thanks! The only part missing would be how to I consider the last twelve months in this formula as well? Should I enter FILTER(DIM_Period[MONTHS]-12?

Hey @EmiliaB_123 ,

 

I think FILTER is a more complicated approach. I would just use DATESINPERIOD.

The formula would then look like this:

Zeros =
CALCULATE(
    COUNTROWS(myTable)
    myTable[ColumnWithZeroValues] = 0,
    DATESINPERIOD (
            'DateTable'[Date],
            MAX ( 'DateTable'[Date] ),
            -1,
            YEAR
    )
)

 

Be aware that the time intelligence functions need a proper date table. Check here how to create a date table if you don't have one:

https://softcrylic.com/blogs/power-bi-for-beginners-how-to-create-a-date-table-in-power-bi/

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

HI @selimovd ,

I have one last question. I tried out the formula with the time reference as well and now I don´t get any values.

EmiliaB_123_0-1626356758572.png

My DIM_Date table looks like this:

EmiliaB_123_1-1626356796302.png

What could be the problem?

 

Thanks.

 

Hey @EmiliaB_123 ,

 

I would guess it's the relationship between the date table and the fact table.

Can you do a double click on the relationship in the relationship view and check if they are connected by the right column?

 

Best regards

Denis

Hi @selimovd ,

looks good to me:

EmiliaB_123_0-1626358947348.png

 

@EmiliaB_123  also looks good for me. I could take a look into the file if it doesn't contain confidential information or if you could remove sensitive data.
Otherwise it's a little hard to say without investigating further.

Hi @selimovd , I checked the definition of DATESINPERIOD and it seems that the output of this formula is a date. What I need is to consider the last year starting from today to count to rows, so the output should be a whole number. Is there maybe another formula that I could check?

Thanks.

@selimovd I unfortunately can´t share the file. Taking the confidential data out of it would also mean to take data out of the formula this problem is referring to. I´ll try to check it by myself. Thank you.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors