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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
KarolSJZ
Frequent Visitor

COUNTIFS and moving ranges in column

Hello,

I am wondering how to write a formula for a column in a table (not measure) in PowerBI that will work by moving ranges.

Below is an example of an implementation using COUNTIFS in Excel. I think the screenshots say it all and I don't need to describe anything else. For clarity, LICZ.WARUNKI = COUNTIFS in Excel.

 

KarolSJZ_2-1620288907534.png

KarolSJZ_3-1620288945356.png

KarolSJZ_5-1620289065591.png

 

Thank you in advance for your help.

Karol

 

 

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @KarolSJZ,

>>If I understood correctly, it is not possible to create such a column with data?

Nope, calculate column also suitable for this processing. (notice: calculate column/table not able to dynamic interaction with filter/slicer effects)

You can add an index column to your table, then you can try to use the 'earlier' function to use the current value and current index as conditions to looping and calculate through the table records.

How To Use The EARLIER Function In Power BI - A DAX Tutorial | Enterprise DNA

Regards,
Xiaoxin Sheng

View solution in original post

Thank you, that helps me a lot to figure out and solve the problem.

I created index column with measure found on this topic.

https://community.powerbi.com/t5/Desktop/Add-calculated-index-column-by-DAX/td-p/72448

index = 
RANKX (
    FILTER (
        yourTable,
        EARLIER ( yourTable[CC] ) = yourTable[CC]
            && EARLIER ( yourTable[Type] ) = yourTable[Type]
            && yourTable[Cluster] = yourTable[Cluster]
            && EARLIER ( yourTable[Status] ) = yourTable[Status]
    ),
    yourTable[Avg-Position],
    ,
    ASC
  

 

View solution in original post

4 REPLIES 4
KarolSJZ
Frequent Visitor

@Anonymousthank you for your response.

If I understood correctly, it is not possible to create such a column with data? Unfortunately, using measures, I will not be able to use relationships between tables.
Is there any other way out?

 

Anonymous
Not applicable

Hi @KarolSJZ,

>>If I understood correctly, it is not possible to create such a column with data?

Nope, calculate column also suitable for this processing. (notice: calculate column/table not able to dynamic interaction with filter/slicer effects)

You can add an index column to your table, then you can try to use the 'earlier' function to use the current value and current index as conditions to looping and calculate through the table records.

How To Use The EARLIER Function In Power BI - A DAX Tutorial | Enterprise DNA

Regards,
Xiaoxin Sheng

Thank you, that helps me a lot to figure out and solve the problem.

I created index column with measure found on this topic.

https://community.powerbi.com/t5/Desktop/Add-calculated-index-column-by-DAX/td-p/72448

index = 
RANKX (
    FILTER (
        yourTable,
        EARLIER ( yourTable[CC] ) = yourTable[CC]
            && EARLIER ( yourTable[Type] ) = yourTable[Type]
            && yourTable[Cluster] = yourTable[Cluster]
            && EARLIER ( yourTable[Status] ) = yourTable[Status]
    ),
    yourTable[Avg-Position],
    ,
    ASC
  

 

Anonymous
Not applicable

Hi @KarolSJZ,

AFAIK, countifs function in excel means the count calculation with filters, you can use the iterator function 'countx' instead.
Power bi data model tables do not include column and row index, you need to use filter functions and conditions to choose specific ranges or records.

measure =
VAR curr =
    MAX ( Table[Index] )
RETURN
    COUNTX (
        FILTER (
            ALLSELECTED ( Table ),
            [Field1] = "conditon1"
                && [Field2] = "condition2"
                && [Index] <= curr
        ),
        [Column]
    )

Notice: Recursion calculations not supported in DAX functions.

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors