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

CountIf in dax with fixed row

Dear Community,

 

how can I transfer this formula in excel to power bi Dax:

(30-COUNTIF(AF$61:AF61,"<>-"))

 

The first value is fixed in the column AF, and the range changes by 1 as it goes, so the next row is calculated like this:  COUNTIF(AF$61:AF62,"<>-"))  and so on as it goes to the next rows.

 

Thank you very much.

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check this:

Measure =
VAR CurDate_ =
    MAX ( 'YourTable'[Date] )
RETURN
    30
        - CALCULATE (
            COUNT ( 'YourTable'[ColumnName] ),
            'YourTable'[Date] <= CurDate_,
            'YourTable'[ColumnName] <> "-"
        )

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check this:

Measure =
VAR CurDate_ =
    MAX ( 'YourTable'[Date] )
RETURN
    30
        - CALCULATE (
            COUNT ( 'YourTable'[ColumnName] ),
            'YourTable'[Date] <= CurDate_,
            'YourTable'[ColumnName] <> "-"
        )

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

AilleryO
Memorable Member
Memorable Member

Hi,

 

So you're looking for a cumulative count with conditions ?

Do you have an index or a date in your data to do cumulative ?

Can you show us some dummy datas so we can help ?

Basically if you want a count per year you can use Time INtellignece function like TOTALYTD, or a CALCULATE with filters in it.

For example :

TOTALYTD([Sales Revenue],Sales[Date Invoice],//Cumulative sum until today from 1st january
ALL(TableDates))//For all dates
or for cumulative with index :
SUM running by lane (Measure) = 
VAR CurrentIndex=SELECTEDVALUE( 'TabData'[Index] )//Current row index
VAR CurrentLane = SELECTEDVALUE( 'TabData'[LaneID] )//Current Lane
RETURN
CALCULATE(
SUMX( 'TabData' , 'TabData'[value] ),//Sum values
ALL( 'TabData'[Date operation] ),//for all dates
'TabData'[Index] <= CurrentIndex,//only for rows before
'TabData'[LaneID] = CurrentLane )//and for the lane computed
 
Hope those patterns will help
Anonymous
Not applicable

Hi AilleryO,

Thank you so much for your reply! I do have date column in my data. 
Can youplease explain this part 

'TabData'[Index] <= CurrentIndex,//only for rows before
'TabData'[LaneID] = CurrentLane )//and for the lane computed

a bit more in detail?

Thank you!

In my case I have an index column on my data with unique number increasing.

So to get a cumulative result, I'm doing the sum of all previous lines (index wise).

In other words, filtering all line before the one being computed (CurrentRow).

The other one with the lane is that in my case I was making a cumulative sum related to diffrent lanes, so I have to filter as well on the same lane as the one being computed (CurrentLane).

 

So if you have a date and no other filter, you just need the Index part of my example but adapted to your date.

Create a variable

CurrentDate = MAX( YourDate) or SELECTEDVALUE( YourDate )

And then use it  :

'TabData'[Date] <= CurrentDate

 

Hope it makes things clearer

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