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

Join 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.

Reply
fpennisi17
Helper III
Helper III

Calculate frequency by sample type

Hi,

I have a table similar to the following one:

 

AssetStateTypeSamples
AAAAA  0X1000
AAAAA  1X200
AAAAA  2X300
AAAAA  3X50
AAAAA  0Y500
AAAAA  1Y130
AAAAA  2Y180
AAAAA  3Y25

 

The only value I have is the number of samples for a given pair of State and Type.

 

I would like to diplay the data on a matrix visual, having States as rows and Type as columns.
I want to have 2 values for each combination, the first one being the number of samples, while the second one the percentage of samples of that type calculated over the total samples of the same type (beside of the state).

 

With the given sample table, for the state 0 row I should obtain:

Samples for type X = 1000

Percentage for type X = 1000/(1000+200+300+50) = 0,645 = 64.5%

Samples for type Y = 1000

Percentage for type Y = 500/(500+130+180+25) = 0,599 = 59.9%

 

I'm sure this should be pretty straightforward with DAX, but I'm facing more difficulties than I thought.

Can someone suggest me how to obtain this result?

 

Thank you.

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Hi, @fpennisi17 , you might want to try this measure,

 

% Type =
DIVIDE (
    MAX ( 'Table'[Samples] ),
    CALCULATE ( SUM ( 'Table'[Samples] ), ALLEXCEPT ( 'Table', 'Table'[Type] ) )
)

Screenshot 2020-11-19 154705.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

3 REPLIES 3
Fowmy
Super User
Super User

@fpennisi17 

Create two measure and add to a matrix;

 

Count = SUM(Table1[Samples])
----------------------------------------------------
Percent = 
DIVIDE(
    [Count],
    CALCULATE(
        [Count],
        ALLSELECTED(Table1[State])
    )
)

Fowmy_0-1605798213394.png

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

 

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

CNENFRNL
Community Champion
Community Champion

Hi, @fpennisi17 , you might want to try this measure,

 

% Type =
DIVIDE (
    MAX ( 'Table'[Samples] ),
    CALCULATE ( SUM ( 'Table'[Samples] ), ALLEXCEPT ( 'Table', 'Table'[Type] ) )
)

Screenshot 2020-11-19 154705.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!

Great!

Thank you!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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