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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
LLJ1221
Helper I
Helper I

Get count in a measure running total

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 A, Running 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]

       

 image001.png

 

My data model : 

image002.jpg

 

 

 

 

 

 

 

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 a solution. 

The solution it's in this pbix : DATA_COUNT_ITEMS.pbix

View solution in original post

2 REPLIES 2
v-rongtiep-msft
Community Support
Community Support

Hi @LLJ1221 ,

Please have a try.

TOTAL_A =
CALCULATE (
    COUNT ( 'Table'[QuantiteA] ),
    FILTER (
        'Table',
        'Table'[YEAR_MONTH] = EARLIER ( 'Table'[YEAR_MONTH] )
            && 'Table'[Article] = EARLIER ( 'Table'[Article] )
    )
)
TOTAL_b =
CALCULATE (
    COUNT ( 'Table'[Quantite B] ),
    FILTER (
        'Table',
        'Table'[YEAR_MONTH] = EARLIER ( 'Table'[YEAR_MONTH] )
            && 'Table'[Article] = EARLIER ( 'Table'[Article] )
            && 'Table'[Quantite B] <> 0
    )
)
result = calculate(COUNT('Table'[Article]),FILTER('Table','Table'[TOTAL_A]<>0&&'Table'[TOTAL_b]<>0))

 

vrongtiepmsft_0-1699855796953.png

 

How to Get Your Question Answered Quickly 

 

If I have misunderstood your meaning, please provide more details with your desired output.

 

Best Regards
Community Support Team _ Rongtie

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

 

 

 

 

I find a solution. 

The solution it's in this pbix : DATA_COUNT_ITEMS.pbix

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.