Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Dear all
I am trying to create a table to caculate the percetage of each number by category among the sum of all categories (here is Day 1, 2, and 3)
Below is an example data set and expect result:
The result I hope to return is in red, which is different from Power BI's default % of grand total.
In Day 1, the 25% of expect return comes from 3 / (3+4+5)
Yet, in Power BI's default, since there are 7 distingush values within those three days, in Day 1, the % of grand total is 3 / 7 = 43%, which is not I need.
Please kindly let me know how I should write the formula. Thank you so much!
Solved! Go to Solution.
No, a many to one shouldn't matter for this. How are you getting the [daily visitors] into your view? Try it with these measures (adjusted slightly).
daily visitor = DISTINCTCOUNT( Visitors[Visitor_Name] )
% of total daily visitor = DIVIDE ( [daily visitor], CALCULATE ( SUMX ( VALUES ( Visitors[Day] ), [daily visitor] ), ALLSELECTED ( Visitors ) ) )
Yes, you are close on the SUMX.
The X iterators (SUMX, MAXX, AVERAGEX, etc) say do a thing over a table of values. The X is the table, the part before the X is the thing it does with the table, the part in the middle is the values it does the thing to. So our formula does three things.
The reason for the ALLSELECTED is so the SUMX for each row ignores the specific day that is on that row and just does the calculation for all the days in the visual. If we didn't include that the denominator would be the same as the numerator because it would keep the filter on Day:
Hello @Anonymous
Give these a try.
# of distinct visitors = DISTINCTCOUNT( Visitors[Visitor_Name] )
% of total daily visitor = DIVIDE ( [# of distinct visitors], CALCULATE ( SUMX ( VALUES ( Visitors[Day] ), [# of distinct visitors] ), ALLSELECTED ( Visitors[Day] ) ) )
Thanks for your quick reply.
The result of your code in my side ends up like this chart below:
I assume that might be because of the one-to-many relationship.
Customer_info
Order_info
Would you mind to adjust the code you shared earlier a little bit?
Thanks again!
No, a many to one shouldn't matter for this. How are you getting the [daily visitors] into your view? Try it with these measures (adjusted slightly).
daily visitor = DISTINCTCOUNT( Visitors[Visitor_Name] )
% of total daily visitor = DIVIDE ( [daily visitor], CALCULATE ( SUMX ( VALUES ( Visitors[Day] ), [daily visitor] ), ALLSELECTED ( Visitors ) ) )
Is it a must to create a seperate new measure (like "daily visitor") here?
You should, yes. If you just pull the column from the table into the visual and set it to distinct count that only works in the 1 visual. If you write a measure you can use it everywhere.
Is my understanding of SUMX correct here?
Also, how does ALLSELECTED work here?
Many thanks!
Yes, you are close on the SUMX.
The X iterators (SUMX, MAXX, AVERAGEX, etc) say do a thing over a table of values. The X is the table, the part before the X is the thing it does with the table, the part in the middle is the values it does the thing to. So our formula does three things.
The reason for the ALLSELECTED is so the SUMX for each row ignores the specific day that is on that row and just does the calculation for all the days in the visual. If we didn't include that the denominator would be the same as the numerator because it would keep the filter on Day:
Thank you so much for this detailed explanation!
@jdbuchanan71 wrote:Yes, you are close on the SUMX.
The X iterators (SUMX, MAXX, AVERAGEX, etc) say do a thing over a table of values. The X is the table, the part before the X is the thing it does with the table, the part in the middle is the values it does the thing to. So our formula does three things.
- Build a table of all unique entries in the Day column.
- Add the value of the [Daily Visitors] measure.
- Sum the amount in the Daily Visitors column.
The reason for the ALLSELECTED is so the SUMX for each row ignores the specific day that is on that row and just does the calculation for all the days in the visual. If we didn't include that the denominator would be the same as the numerator because it would keep the filter on Day:
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
96 | |
77 | |
66 | |
53 |
User | Count |
---|---|
144 | |
105 | |
102 | |
89 | |
63 |