我有一个表,我想在每个过滤器上更新“百分比值”度量的值(用户可以从切片器中选择一个或多个值)。在可视化中,一年、月的所有标记都需要添加到 1.0 有或没有切片器选择。
在@Phil Leh 的帮助下(在 PowerBI 中使用 ALLEXCEPT 实现分组百分比的问题)措施适用于年、月,并且该措施给出了正确的值:
但是,我不确定我可以做些什么来更新多个选择的 % 值。例如,这里对于 Race 和 Year, Month 在每年的 Year, Month 中,百分比值不会计算为 1.0:
我对现有的 DAX 进行了更改(根据年、月提供正确的值),以便它也可以捕获 Race。但结果是错误的。
Percent Values =
VAR num =
CALCULATE( SUM ( question[Count Values] ))
-- this one filters month and year
VAR fmy =
FILTER (
-- clear all filter from our table
ALL ( question ),
-- and keep only the values matching the
-- filter context's current month and year
question[Date].[Month]
= MAX ( question[Date].[Month] )
&& question[Date].[Year]
= MAX ( question[Date].[Year] )
--|| question[Race]
-- = MAX ( question[Race] )
--|| question[Gender]
-- = MAX( question[Gender] )
--|| question[visa_country]
-- = MAX( question[visa_country] )
)
VAR fr =
FILTER (
-- clear all filter from our table
ALL ( question ),
-- and keep only the values matching the
-- filter context's current month and year
question[Race]
= MAX ( question[Race] )
)
VAR denom =
IF (
-- checking if Month is in current filter context
ISINSCOPE ( question[Date].[Month] ), --|| ISINSCOPE ( question[Race] ) || ISINSCOPE ( question[Gender] ) || ISINSCOPE (question[visa_country] ),
-- if yes, use the filter fmy (calculate denom for this quarter
CALCULATE (
SUM ( question[Count Values] ),
ALLSELECTED (),
fmy
),
--IF (
-- ISINSCOPE ( question[Race] ),
-- CALCULATE (
-- SUM ( question[Count Values] ),
-- ALLSELECTED (),
-- fr
-- ),
-- else, calculate the denom for all values
-- this could also be BLANK() or some other calculation
-- CALCULATE (
-- SUM ( question[Count Values] ),
-- ALLSELECTED ()
-- )
--)
CALCULATE (
SUM ( question[Count Values] ),
ALLSELECTED ()
)
)
RETURN
DIVIDE (
num,
denom
)
在上面的照片中,没有重新计算 % 值。
以下是 .csv 格式的数据:
Race,Gender,visa_type,Count Values,visa_country,Processing Type,Date
White,Female,C,1,Canada,Custodial,2/14/2014 0:00
Other,Male,M,5,Mexico,Express,1/20/2015 0:00
Hispanic,Male,R,6,Russia,Refugee,2/18/2014 0:00
White,Female,B,4,Brazil,Asylum,3/7/2014 0:00
Hispanic,Male,C,1,Canada,Refugee,4/11/2015 0:00
White,Female,R,7,Russia,Custodial,4/23/2014 0:00
White,Male,M,9,Mexico,Express,4/1/2014 0:00
Hispanic,Male,B,3,Brazil,Refugee,4/13/2014 0:00
White,Female,R,1,Russia,Express,7/31/2014 0:00
White,Male,C,7,Canada,Asylum,9/6/2015 0:00
White,Female,M,2,Mexico,Express,7/22/2014 0:00
Black,Female,B,5,Brazil,Custodial,8/13/2014 0:00
White,Male,R,1,Russia,Asylum,12/9/2014 0:00
White,Female,M,4,Mexico,Asylum,12/6/2014 0:00
Black,Female,B,6,Brazil,Express,12/13/2015 0:00
White,Male,C,7,Canada,Refugee,10/26/2014 0:00
Hispanic,Female,R,5,Brazil,Refugee,9/6/2015 0:00
White,Male,B,9,Mexico,Asylum,9/6/2015 0:00
.xlsx 文件:https ://github.com/TestingGround00/powerbi_question/blob/main/input_data_table.xlsx
我已经制作了另一个 DAX,它现在在整个子集中提供 100%,但它确实需要在每年、每月有和/或没有切片器的情况下添加 100%。
Sum Value = SUM ( Table[Count Values] )
% Value =
DIVIDE (
[Sum Value],
CALCULATE ( [Sum Value], ALLSELECTED ( ) )
)
我看过这些问题,但是它们有些无关紧要:
如果没有切片器选择,我需要这个输出-
然而,随着 Smpa01 的帖子没有切片器数据的变化 -