The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi,
I have a table similar to the following one:
Asset | State | Type | Samples |
AAAAA | 0 | X | 1000 |
AAAAA | 1 | X | 200 |
AAAAA | 2 | X | 300 |
AAAAA | 3 | X | 50 |
AAAAA | 0 | Y | 500 |
AAAAA | 1 | Y | 130 |
AAAAA | 2 | Y | 180 |
AAAAA | 3 | Y | 25 |
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.
Solved! Go to Solution.
Hi, @fpennisi17 , you might want to try this measure,
% Type =
DIVIDE (
MAX ( 'Table'[Samples] ),
CALCULATE ( SUM ( 'Table'[Samples] ), ALLEXCEPT ( 'Table', 'Table'[Type] ) )
)
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! |
@fpennisi17
Create two measure and add to a matrix;
Count = SUM(Table1[Samples])
----------------------------------------------------
Percent =
DIVIDE(
[Count],
CALCULATE(
[Count],
ALLSELECTED(Table1[State])
)
)
________________________
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 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Hi, @fpennisi17 , you might want to try this measure,
% Type =
DIVIDE (
MAX ( 'Table'[Samples] ),
CALCULATE ( SUM ( 'Table'[Samples] ), ALLEXCEPT ( 'Table', 'Table'[Type] ) )
)
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!
User | Count |
---|---|
24 | |
9 | |
8 | |
7 | |
6 |
User | Count |
---|---|
29 | |
13 | |
11 | |
10 | |
9 |