Calculating % by Dividing Filtered Matrix Columns from Tables Related on 2 Attributes in MS Power BI

只愿长相守 提交于 2020-01-25 06:40:24

问题


This question is related to a simpler problem, posted here: Calculating % by Dividing Filtered Matrix Columns in MS Power BI

Given: There are 2 (or more) attributes (e.g. 'Date' and 'Location') rather than just 1 (e.g. 'Date'), on which the tables have to be connected. In this case, both tables have to be filtered by date, as well as location, as in the following example:

Table 4:

Date_1  Location_1  Numerator
01-Jan-19   NY      5
05-Feb-19   CA      4
04-Apr-19   WA      1
07-May-19   OR      3
11-Jun-19   ND      5
22-Jun-19   NY      4
25-Jul-19   MN      5
31-Aug-19   NY      1
03-Sep-19   NY      4
25-Oct-19   MI      5

Table 5:

Date_2  Location_2  Denominator
03-Jan-19   NY      7
05-Jan-19   NY      9
16-Feb-19   CA      8
22-Feb-19   CA      7
04-Mar-19   AZ      10
18-Mar-19   ND      8
24-Apr-19   WA      8
25-Apr-19   WA      8
01-May-19   OR      10
10-May-19   OR      8
04-Jun-19   ND      8
08-Jun-19   NY      7
03-Jul-19   MN      8
18-Jul-19   MN      6
23-Aug-19   NY      10
31-Aug-19   NY      9
03-Sep-19   NY      9
20-Sep-19   NY      7
03-Oct-19   MI      7
27-Oct-19   MI      6

Tables 4 and 5 can be pivoted to get something like the following:

Table 4 Pivot:

Sum of Numerator                2019 Months                     
    Jan Feb Mar Apr May Jun Jul Aug Sep Oct Location Total
Location                                            
CA      4                                   4
MI                                      5   5
MN                          5               5
ND                      5                   5
NY  5                   4       1   4       14
OR                  3                       3
WA              1                           1
Total 5 4       1   3   9   5   1   4   5   37

Table 5 Pivot:

Sum of Denominator  2019 Months                                     
    Jan Feb Mar Apr May Jun Jul Aug Sep Oct Location Total
Location                                            
AZ          10                              10
CA      15                                  15
MN                          14              14
ND          8           8                   16
NY  16                  7       19  16      58
OR                  18                      18
WA              16                          16
MI                                      13  13
Total 16 15 18  16  18  15  14  19  16  13  160

The desired output is as follows:

Table 6:

                2019 Months                                     
    Jan    Feb      Mar     Apr     May     Jun     Jul     Aug     Sep     Oct    Location Total
Location                                            
CA                                                                          38.46%  38.46%
MN                                                  35.71%                          35.71%
ND                  0.00%                   62.50%                                  31.25%
NY  31.25%                                  57.14%          5.26%   25.00%          24.14%
OR                                  16.67%                                          16.67%
WA                          6.25%                                                   6.25%
Ttl 31.25%  26.67%  0.00%   6.25%   16.67%  60.00%  35.71%  5.26%   25.00%  38.46%  23.13%

Problem: The % calculated in Power BI is wrong, when the data are visualized in Matrix format similar to Table 6. I thought that Tables 4 and 5 could be linked with connecting them all on 'Location' and 'Date' attributes by using unique calendar and location lists. However, this does not work, because "Ambiguous paths..." error is generated when trying to connect Table 4 and 5 with calendar table, each on 'Date' attribute, and also Table 4 and 5 with location table, each on 'Location' attribute.

Question: How can one obtain correct results as in Table 6 in Power BI, using the equivalent of Tables 4 and 5?

Data relationship diagram can be found here.

来源:https://stackoverflow.com/questions/59868495/calculating-by-dividing-filtered-matrix-columns-from-tables-related-on-2-attri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!