Давайте сделаем все в одном go, используя настраиваемую таблицу и GROUP BY. Создайте «Новую таблицу» с приведенным ниже кодом, нажав кнопку, показанную на изображении ниже -
Now just paste this following code in the script section-
Considered your base table name = percentage_subcategory.
Please change the table name reference accordingly.
group_by_sub_category =
VAR sub_category_wise_total =
GROUPBY (
percentage_subcategory,
percentage_subcategory[YearMonth],
percentage_subcategory[PercentRange],
"sum_sub1",
SUMX(
CURRENTGROUP()
,
IF(
percentage_subcategory[SubCategory] = "Sub1",
percentage_subcategory[TotalCount],
BLANK()
)
)
,
"sum_sub2",
SUMX(
CURRENTGROUP()
,
IF(
percentage_subcategory[SubCategory] = "Sub2",
percentage_subcategory[TotalCount],
BLANK()
)
)
,
"sum_total_count", SUMX(CURRENTGROUP(), percentage_subcategory[TotalCount])
)
RETURN
SELECTCOLUMNS (
sub_category_wise_total,
"YearMonth",percentage_subcategory[YearMonth],
"PercentRange",percentage_subcategory[PercentRange],
"sum_sub1",[sum_sub1],
"sum_sub2",[sum_sub2],
"sum_total_count", [sum_total_count],
"sub1_percentage",([sum_sub1]/[sum_total_count]),
"sub2_percentage",([sum_sub2]/[sum_total_count])
)
Now you have a new table in the report source with name "group_by_sub_category". Just change the data type of column "sub1_percentage" & "sub2_percentage" to Percentage by selecting both columns and click on the % sign in the top menu as shown in the below image-
введите описание изображения здесь