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

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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

@v-shex-msftthank 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?

 

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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
  

 

v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.