Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
11 | |
10 | |
9 | |
8 |
User | Count |
---|---|
17 | |
12 | |
11 | |
11 | |
11 |