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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
LLJ1221
Helper I
Helper I

Get count of rows in running total measure

Hello,

 

I am a beginner in Power BI and I have a problem calculating the number of occurrences of measure.

 

I have 2 problems : 

1) I want to know the number of distinct item items I have in measure "Difference Running Total A & B"

Example, in my table , i have 2 article in september 2023. Which formula dax i can do ?

 

2) I want to know the number of items difference from zero in measure "Difference Running Total A & B"

in my example, i have 2 article with difference running total A&B <>0

 

My data it's Year, Month, Article and Storage.
I calculate Running total ARunning total B and Difference Running Total A&B in Power bi with measures

 

Running total A = CALCULATE(

        SUM( 'Table'[QuantiteA] ),

        FILTER(

            ALLSELECTED( 'CALENDAR' ),

            'CALENDAR'[Date]

                <= MAX('CALENDAR'[Date] )

        ))

 

Running total B = CALCULATE(

        SUM( 'Table'[Quantite B] ),

        FILTER(

            ALLSELECTED( 'CALENDAR' ),

            'CALENDAR'[Date]

                <= MAX('CALENDAR'[Date] )

        ))

       

Difference Running Total A&B = [Running total A] - [Running total B]

 

LLJ1221_0-1699635444497.png

 

My data model : 

LLJ1221_1-1699635444516.jpeg

To better understand my problem, I created a pbix file which can be downloaded via One Drive : https://1drv.ms/u/s!AjUN6-w6YnuGz1ng157xR5Ha7h_x

1 ACCEPTED SOLUTION

I find the solution. 

The solution is in this pbix here : DATA_COUNT_ITEMS.pbix

View solution in original post

8 REPLIES 8
LLJ1221
Helper I
Helper I

Hi @some_bih 

 

Thank you for your feedback and for this explanation.

I'm a beginner in Power BI and I spent a lot of time trying to write these measures with "ALLSELECTED".

How could I rewrite these measurements please?

Thanks

Hi @LLJ1221 something went wrong so I could not open your file.

Try two measures below

Test A=

VAR __max_date = MAX ( 'Calendar'[Date] ) 

RETURN

    CALCULATE (

         SUM( 'Table'[QuantiteA] ),           

        'Calendar'[Date] <= __max_date 

        ALL ( 'Calendar' )             

    )

 

 

Test B=

VAR __max_date = MAX ( 'Calendar'[Date] ) 

RETURN

    CALCULATE (

        SUM( 'Table'[Quantite B] )           

        'Calendar'[Date] <= __max_date 

        ALL ( 'Calendar' )             

    )





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






 Thanks you, I modifiy my dax formula and it's ok. 

 

But i try to count number of article i have and number of article with difference between cumul A & B is zero and the résult is bad. 

LLJ1221_0-1699880106368.png

 

DAX Formula for count number of article (items) : 

Nb item = CALCULATE(DISTINCTCOUNT('Table'[ITEM]), FILTER(ALLSELECTED('Calendar'), 'Calendar'[Date].[Date] <= MAX('Calendar'[Date].[Date]) && (NOT ISBLANK([Diff_cumulAB]))))Dax

 formula for count number of article with Diff_cumulAB =0 Nb item equal 0 = 

CALCULATE(DISTINCTCOUNT('Table'[ITEM]), FILTER(ALLSELECTED('Calendar'), 'Calendar'[Date].[Date] <= MAX('Calendar'[Date].[Date]) && [Diff_cumulAB]=0))

Normally I should have 5 items and 2 items whose last digit "Diff_cumulAB" is equal to 0

 

 

--formulas (both of them) after FILTER - filters Calendar table and [Diff_cumulAB]
--[Diff_cumulAB] is not part of Calendar table? If yes then rewrite formula





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Why I have to rewrite the formula given that it works, I don't quite understand.

thanks anyway

Hi @LLJ1221 CALCULATE formula usually filter argument, still the filters could be inserted simply using commas

filter1, filter1....

In your case I do not understand what is [Diff_cumulAB] but you use it in part formulas (both of them) after FILTER - filters Calendar table





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






I find the solution. 

The solution is in this pbix here : DATA_COUNT_ITEMS.pbix

some_bih
Super User
Super User

Hi @LLJ1221 your measure use reference to another measure which use ALLSELECTED. This is not best practice as result is hard to interpret; hard to spot unlogical output in results. ALLSELECTED is best used for visuals.

Rewrite your measure/s.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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