我最近开始使用PowerBI并学习DAX。我想将条件伪代码转换为DAX,这将导致名为“ Percentage”的列。因此,我的表由公司列(Dole,Dyson,孟山都等),水果名称(苹果,香蕉,梨,西红柿,黄瓜等)和食品组(蔬菜,肉等)组成。 )
Company | Fruit Name | Food Group
----------------------------------
Dole | Apple | Fruit
Dyson | Chicken | Meat
Dole | Pear | Fruit
Dole | Tomato | Vegetable
这是条件代码的伪代码:
if(FruitName = 'Apple') //for the rows that have 'Apples'
then( 1/count( Food Group for Company) ) //percentage of apples within
//Fruits distributed by Company: probably a groupby
else (1/count(Food Group for Company) ) //percentage of value within 'Food Group' by Company
结果将在度量内输出,是百分比列。
Company | Fruit Name | Food Group | Percentage
-----------------------------------------------------
Dole | Apple | Fruit | 33.33%
Dyson | Chicken | Meat | 100%
Dole | Pear | Fruit | 33.33%
Dole | Banana | Fruit | 33.33%
Dole | Tomato | Vegetable | 100%
您能告诉我一种用DAX编写此条件的方法吗?
谢谢