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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Counting rows with lower value

Good day, 

I am trying to calculate the number of rows that have a value of 'Sąnaudos' lower than the line in question. In every line of this table it should show how many lines there are with values lower, than the value of this line. 
I am trying to do it like this, but don't know how to compare value of column to the value of the same column.
No of lower values = CALCULATE(COUNTROWS('Sąnaudų lentelė'), 'Sąnaudų lentelė'[Sąnaudos] < what?

almafater2_0-1621256417148.png

 

Or should I use a different DAX approach? 

 

 

1 ACCEPTED SOLUTION

Hi  @Anonymous 

thank you for your reply.

Because you have same VII ID, and property of column Sąnaudos is Sum, so it will categorize automatically according to VII ID in table visual. If you don’t need total row, you can change the property to Dont summarize,

Result:

v-xiaotang_0-1622449230243.png

Or if you need total row, try this.

Create the 2  measure:

 

calculatesum = CALCULATE(SUM('Sąnaudų lentelė'[Sąnaudos]),ALLEXCEPT('Sąnaudų lentelė','Sąnaudų lentelė'[VII ID]))
No of lower values = RANKX(ALL('Sąnaudų lentelė'),[calculatesum],,,Dense)

 

FYI:https://docs.microsoft.com/en-us/dax/rankx-function-dax

 

Result:

v-xiaotang_1-1622449230248.png

 

Best Regards,

Community Support Team _ Tang

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

View solution in original post

8 REPLIES 8
FrankAT
Community Champion
Community Champion

Hi @Anonymous ,

I think you can do it like this:

 

19-05-_2021_15-58-02.png

 

 

 

No of lower values = 
VAR _MaxValue =
    CALCULATE ( MAX ( 'Sąnaudų lentelė'[Skirtumas] ), ALL ( 'Sąnaudų lentelė' ) )
RETURN
    CALCULATE (
        COUNTROWS ( 'Sąnaudų lentelė' ),
        FILTER (
            ALL ( 'Sąnaudų lentelė' ),
            MIN ( 'Sąnaudų lentelė'[Sąnaudos] ) <= _MaxValue
                && 'Sąnaudų lentelė'[Sąnaudos] > MIN ( 'Sąnaudų lentelė'[Sąnaudos] )
        )
    )

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

Anonymous
Not applicable

Thank you, I applied the formula "No of lover values" in the exaple file. 

 

I am getting closer, but something in this formula is still not giving the results I was hopping for:

 

https://www.dropbox.com/s/jlapxus5a3i6kee/Example.pbix?dl=0

 

What am I missing? 

 

v-xiaotang
Community Support
Community Support

Hi @Anonymous 

Not very clear your expected result, but you can take sample file attached bellow for reference.

-

Create the measure:

 

No of lower values =
CALCULATE(COUNTROWS('Table'),FILTER(ALL('Table'),'Table'[Sanaudos]<SELECTEDVALUE('Table'[Sanaudos])))

 

Result:

v-xiaotang_0-1621421345745.png

 

Best Regards,

Community Support Team _ Tang

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

Anonymous
Not applicable

Hey, thank you that was the result what I was expectecting, but as I applied it in my data setup it did not give me the same result. I am attaching a PBI desktop file for more context:
Example 
What I am trying to achieve here is count the percentile of Sąnaudos (expences), for every VII ID. For that I need a count of VII that have lower value of Sąnaudos, than the selected value. Does that make sence? 

Hi  @Anonymous 

thank you for your reply.

Because you have same VII ID, and property of column Sąnaudos is Sum, so it will categorize automatically according to VII ID in table visual. If you don’t need total row, you can change the property to Dont summarize,

Result:

v-xiaotang_0-1622449230243.png

Or if you need total row, try this.

Create the 2  measure:

 

calculatesum = CALCULATE(SUM('Sąnaudų lentelė'[Sąnaudos]),ALLEXCEPT('Sąnaudų lentelė','Sąnaudų lentelė'[VII ID]))
No of lower values = RANKX(ALL('Sąnaudų lentelė'),[calculatesum],,,Dense)

 

FYI:https://docs.microsoft.com/en-us/dax/rankx-function-dax

 

Result:

v-xiaotang_1-1622449230248.png

 

Best Regards,

Community Support Team _ Tang

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

Anonymous
Not applicable

Thank you,!

amitchandak
Super User
Super User

@Anonymous , You can create a what if parameter and use that

 

Inplace of ?

selectedvalue(whatif[Param])

 

https://docs.microsoft.com/en-us/power-bi/desktop-what-if

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thank you for the reply. 

1. Selectedvalue function can't be used in the way you recomended. 

almafater2_0-1621260560726.png

 

2. I don't understant what type of what if parameter could help in this situation. 


Helpful resources

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

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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