Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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]
My data model :
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
Solved! Go to Solution.
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' )
)
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.
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
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
Proud to be a 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.
Proud to be a Super User!
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
22 | |
7 | |
6 | |
6 | |
6 |
User | Count |
---|---|
27 | |
10 | |
10 | |
9 | |
6 |