我有这个DAX:
import React from 'react';
import { makeStyles, withStyles } from '@material-ui/core/styles';
import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
import FormControl from '@material-ui/core/FormControl';
import Select from '@material-ui/core/Select';
import NativeSelect from '@material-ui/core/NativeSelect';
import InputBase from '@material-ui/core/InputBase';
const BootstrapInput = withStyles(theme => ({
root: {
'label + &': {
marginTop: theme.spacing(3),
},
},
input: {
borderRadius: 4,
position: 'relative',
backgroundColor: theme.palette.background.paper,
border: '1px solid #ced4da',
fontSize: 16,
width: 'auto',
padding: '10px 26px 10px 12px',
transition: theme.transitions.create(['border-color', 'box-shadow']),
// Use the system font instead of the default Roboto font.
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
'&:focus': {
borderRadius: 4,
borderColor: '#80bdff',
boxShadow: '0 0 0 0.2rem rgba(0,123,255,.25)',
},
},
}))(InputBase);
const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
flexWrap: 'wrap',
},
margin: {
margin: theme.spacing(1),
},
}));
export default function CustomizedSelects() {
const classes = useStyles();
const [age, setAge] = React.useState('');
const handleChange = event => {
setAge(event.target.value);
};
return (
<form className={classes.root} autoComplete="off">
<FormControl className={classes.margin}>
<InputLabel htmlFor="age-customized-input">Age</InputLabel>
<BootstrapInput id="age-customized-input" />
</FormControl>
<FormControl className={classes.margin}>
<InputLabel htmlFor="age-customized-select">Age</InputLabel>
<Select
value={age}
onChange={handleChange}
input={<BootstrapInput name="age" id="age-customized-select" />}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
<FormControl className={classes.margin}>
<InputLabel htmlFor="age-customized-native-simple">Age</InputLabel>
<NativeSelect
value={age}
onChange={handleChange}
input={<BootstrapInput name="age" id="age-customized-native-simple" />}
>
<option value="" />
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</NativeSelect>
</FormControl>
</form>
);
}
Earned Daily =
VAR d = SELECTEDVALUE ( 'P6 Update'[Date] )
RETURN
IF (
'Data for Pivot'[Date] <= d
&& 'Data for Pivot'[Act Rem] = "Actual Units"
&& 'Data for Pivot'[Type] = "Current",
'Data for Pivot'[Value],
0
)
附加到切片器(单选日期下拉列表)。
我看到正确设置了日期,但是当我尝试使用日期进行过滤时,则无法正常工作。
如果我这样做:
'P6 Update'[Date]
数据已正确过滤。
原始代码有什么问题?
#######
注意:P6更新表是使用以下代码创建的:
Earned Daily =
IF (
'Data for Pivot'[Date] <= DATE ( 2018, 4, 19 )
&& 'Data for Pivot'[Act Rem] = "Actual Units"
&& 'Data for Pivot'[Type] = "Current",
'Data for Pivot'[Value],
0
)
答案 0 :(得分:1)
您的DAX公式似乎是计算所得的列,而不是度量。由于计算列仅在每次加载表时进行一次评估,因此它们无法响应切片器或任何类型的动态过滤。
解决方案是编写一个度量以产生所需的值。看起来像这样:
Earned Daily =
VAR d = SELECTEDVALUE ( 'P6 Update'[Date] )
RETURN
CALCULATE (
SUM ( 'Data for Pivot'[Value] ),
'Data for Pivot'[Date] <= d,
'Data for Pivot'[Act Rem] = "Actual Units",
'Data for Pivot'[Type] = "Current"
)
您可能需要根据尝试使用此度量的环境进行调整,但这是基本方法。
答案 1 :(得分:0)
根据@Alexis Olson的回答,我整理出了一个完全符合我想要的内容:
Earned Daily =
VAR d = SELECTEDVALUE ( 'P6 Update'[Date] )
RETURN
CALCULATE (
SUM('Data for Pivot'[Value] ),
FILTER(ALLSELECTED('Data for Pivot'),'Data for Pivot'[Date]=MAX('Data for Pivot'[Date])),
'Data for Pivot'[Date] <= d,
'Data for Pivot'[Act Rem] = "Actual Units",
'Data for Pivot'[Type] = "Current"
)
添加了FILTER,使其按日期匹配Date 直到到达
'P6 Update'[Date]
。