通过在MS Power BI中划分过滤矩阵列来计算% [英] Calculating % by Dividing Filtered Matrix Columns in MS Power BI
问题描述
给出:必须通过将一个表中的一列(分子")除以另一张表中的一列(分母")来计算每月百分比(%)指标,两者均按一个月,如以下示例所示:
表1:
Date_1分子19年1月1日519年2月5日419年4月4日119年5月7日319年6月11日519年6月22日419年7月25日519年8月31日119年9月3日419年10月25日5
表2:
Date_2分母19年1月3日719年1月5日919年2月16日819年2月22日719年3月4日1019年3月18日819年4月24日819年4月25日819年5月1日1019年5月10日819年6月4日819年6月8日719年7月3日819年7月18日619年8月23日1019年8月31日919年9月3日919年9月20日719年10月3日719年10月27日6
解决此任务的一种方法是在MS Excel中使用数据透视表,方法是将分子"中的行除以分母"中与过滤后的"Date_1"和"Date_2"列中相同月份相对应的行,然后将结果格式化为%,如下表3所示:
表3:
Month_1分子月份的总和_2分母月份的总和%1月5日1月16日1月31.25%2月4日2月15日2月15日26.67%3月3月18日3月0.00%4月1日4月16日4月6.25%5月3日5月18日5月18日16.67%6月9日6月15日6月60.00%7月5日7月14日7月35.71%8月1日8月19日8月19日5.26%9月4日9月16日9月25.00%10月5日10月13日10月38.46%十一月十一月十一月十二月十二月十二月总计37总计160总计23.13%
MS Power BI用于从数据库中自动查询数据,但是问题在于数据透视表(在Power BI中用矩阵表示)的划分.
问题:如何使用表1和表2的等效项从Power BI中的表3中获得与月"和%"列的等效输出?我是Power BI的新手,不确定是什么问题以及如何解决它.
您需要创建一个
然后使用日期字段将其连接到表格:
创建3种简单的DAX措施:
Sum Nominator = SUM(表1 [Nominator])分母和= SUM(表2 [分母])总计百分比=除数([总分母],[总分母])
将月份"放到枢轴上,然后添加3个小节:
Given: A monthly percentage (%) metric has to be calculated from dividing a column ('Numerator') from one table by a column ('Denominator') from another table, both filtered by month, as given in an example below:
Table 1:
Date_1 Numerator
01-Jan-19 5
05-Feb-19 4
04-Apr-19 1
07-May-19 3
11-Jun-19 5
22-Jun-19 4
25-Jul-19 5
31-Aug-19 1
03-Sep-19 4
25-Oct-19 5
Table 2:
Date_2 Denominator
03-Jan-19 7
05-Jan-19 9
16-Feb-19 8
22-Feb-19 7
04-Mar-19 10
18-Mar-19 8
24-Apr-19 8
25-Apr-19 8
01-May-19 10
10-May-19 8
04-Jun-19 8
08-Jun-19 7
03-Jul-19 8
18-Jul-19 6
23-Aug-19 10
31-Aug-19 9
03-Sep-19 9
20-Sep-19 7
03-Oct-19 7
27-Oct-19 6
One way this task can be solved is by using pivot tables in MS Excel by dividing the rows from 'Numerator' by rows from 'Denominator' corresponding to the same months in filtered 'Date_1' and 'Date_2' columns, and then formatting the results as %, as shown in Table 3 below:
Table 3:
Month_1 Sum of Numerator Month_2 Sum of Denominator Month %
Jan 5 Jan 16 Jan 31.25%
Feb 4 Feb 15 Feb 26.67%
Mar Mar 18 Mar 0.00%
Apr 1 Apr 16 Apr 6.25%
May 3 May 18 May 16.67%
Jun 9 Jun 15 Jun 60.00%
Jul 5 Jul 14 Jul 35.71%
Aug 1 Aug 19 Aug 5.26%
Sep 4 Sep 16 Sep 25.00%
Oct 5 Oct 13 Oct 38.46%
Nov Nov Nov
Dec Dec Dec
Grand Total 37 Grand Total 160 Grand Total 23.13%
MS Power BI is used for querying the data automatically from the database, but the problem arises with division of pivot tables (which are represented as matrices in Power BI).
Question: How can one obtain an equivalent output to 'Month' and '%' columns from Table 3 in Power BI using the equivalent of Tables 1 and 2? I am new to Power BI and and am not sure of what the problem is and how to correct it.
You need to create a Calendar Table, and connect it to both tables.
For example, create a calendar (Date) table like this:
Then connect it to your tables using date fields:
Create 3 simple DAX measures:
Sum Nominator = SUM(Table1[Nominator])
Sum Denominator = SUM(Table2[Denominator])
Total % = DIVIDE( [Sum Nominator], [Sum Denominator])
Drop Month into a pivot, and then add 3 measures:
这篇关于通过在MS Power BI中划分过滤矩阵列来计算%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!