如何减去另一行的值取决于PowerBI中的类别列
How to subtract the value of another row depends on Category column in PowerBI
这是图片说明
我想在“其他服务”中显示NewLinePrice,该值将减去“平面设计”的值,因此第一列将显示1152245,依此类推。
到目前为止,我已经尝试定义新列“NewLinePrice”,以下是公式但不起作用
NewLinePrice =
Var category = 'Group-dtl'[ProductCategoryName]
var graphic_line_price = CALCULATE(SUM('Group-dtl'[LinePrice]),FILTER('Group-dtl', 'Group-dtl'[ProductCategoryName] = "Graphic Design"))
var graphic_line_price_temp = IF(category = "Graphic Design", 'Group-dtl'[LinePrice], 0)
//var graphic_line_price = 1
Var pre_result = IF(category = "Other Service", 'Group-dtl'[LinePrice] - graphic_line_price, BLANK())
Var result = IF(pre_result > 0, pre_result, BLANK())
return result
有人知道怎么做吗?
我花了一些时间来寻找你的问题的答案,最后我发现要达到你的结果,你不能在原来的范围内进行计算,而是要创建一个新的table,原因是未知,但至少它是可以实现的,请参阅下面的答案并接受如果有帮助,感谢我的辛勤工作:)
这是我原来的table名字[Sheet1]
首先我在原来的table
的基础上新建了一个table
Table =
ADDCOLUMNS(VALUES(Sheet1[Product Name]),
"Sales",CALCULATE(SUM(Sheet1[Amount]),
FILTER(ALL(Sheet1),Sheet1[Product Name]=EARLIER(Sheet1[Product Name]))))
在新 table 中,我使用以下公式将新列添加到 return 仅针对“其他服务”的不同值
New Line1 =
Var ServiceValue = CALCULATE(MAX(Sheet1[Amount]),Sheet1[Product Name] = "Other Service")
Var graphicValue = CALCULATE(MAX(Sheet1[Amount]),Sheet1[Product Name] = "Graphic Design")
Var charge = ServiceValue - graphicValue
return
if('Table'[Product Name] = "Other Service", charge,'Table'[Sales])
这是具有更新值的新 table:
这是图片说明
我想在“其他服务”中显示NewLinePrice,该值将减去“平面设计”的值,因此第一列将显示1152245,依此类推。
到目前为止,我已经尝试定义新列“NewLinePrice”,以下是公式但不起作用
NewLinePrice =
Var category = 'Group-dtl'[ProductCategoryName]
var graphic_line_price = CALCULATE(SUM('Group-dtl'[LinePrice]),FILTER('Group-dtl', 'Group-dtl'[ProductCategoryName] = "Graphic Design"))
var graphic_line_price_temp = IF(category = "Graphic Design", 'Group-dtl'[LinePrice], 0)
//var graphic_line_price = 1
Var pre_result = IF(category = "Other Service", 'Group-dtl'[LinePrice] - graphic_line_price, BLANK())
Var result = IF(pre_result > 0, pre_result, BLANK())
return result
有人知道怎么做吗?
我花了一些时间来寻找你的问题的答案,最后我发现要达到你的结果,你不能在原来的范围内进行计算,而是要创建一个新的table,原因是未知,但至少它是可以实现的,请参阅下面的答案并接受如果有帮助,感谢我的辛勤工作:)
这是我原来的table名字[Sheet1]
首先我在原来的table
的基础上新建了一个tableTable =
ADDCOLUMNS(VALUES(Sheet1[Product Name]),
"Sales",CALCULATE(SUM(Sheet1[Amount]),
FILTER(ALL(Sheet1),Sheet1[Product Name]=EARLIER(Sheet1[Product Name]))))
在新 table 中,我使用以下公式将新列添加到 return 仅针对“其他服务”的不同值
New Line1 =
Var ServiceValue = CALCULATE(MAX(Sheet1[Amount]),Sheet1[Product Name] = "Other Service")
Var graphicValue = CALCULATE(MAX(Sheet1[Amount]),Sheet1[Product Name] = "Graphic Design")
Var charge = ServiceValue - graphicValue
return
if('Table'[Product Name] = "Other Service", charge,'Table'[Sales])
这是具有更新值的新 table: