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
Dunner2020
Post Prodigy
Post Prodigy

Calculate percentage of selected year

Hi there,

 

I am trying to calculate the percentage of events that occurred at a location. I want to calculate the percentage in such a way that if I select the year from the slicer then it gives me the percentage of events that occurred in the selected year. If nothing is selected then it gives a percentage of all years. 

 

I am calculating measure something like that:

 

No of events = CALCULATE( DISTINCTCOUNT('Main Table'[OutageID]), FILTER('Main Table', 'Main Table'[Actual Interruption Start Time (NZST)] <= Today()))
Percentage =
Var _total_events = CALCULATE([No of events],ALLEXCEPT('Date','Date'[RY Year]))
Return
CALCULATE(([No of events] / _total_events)*100)
 
However, I got the following output
 
leo_89_0-1622421267275.png

Could anyone help me where I made the mistake?

Sample file here

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

# Events = DISTINCTCOUNT( 'Main Table'[OutageID] )
Pct = 
DIVIDE(
    [# Events],
    CALCULATE( [# Events], ALLEXCEPT( 'Main Table', 'Date'[RY] ) )
)

Screenshot 2021-05-31 035943.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

1 REPLY 1
CNENFRNL
Community Champion
Community Champion

# Events = DISTINCTCOUNT( 'Main Table'[OutageID] )
Pct = 
DIVIDE(
    [# Events],
    CALCULATE( [# Events], ALLEXCEPT( 'Main Table', 'Date'[RY] ) )
)

Screenshot 2021-05-31 035943.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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